You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Comma Separated Values (CSV) Providers

Apache Wink provides a CSV data model and providers for producing and consuming CSV (text/csv). The model is based on a Serialization and a Deserialization interface, in addition to a simple CSV Table class. All of the model classes are located under the com.hp.symphony.common.model.csv package.

The following tables list the providers that provide this functionality.

 

Supported

Media Types

Data Model

Provider registration

Read

Yes

text/csv

org.apache.wink.common.model.csv.CsvDeserializer,
org.apache.wink.common.model.csv.CsvTable,
org.apache.wink.common.model.csv.MultiCsvTable

Not required. Registered by default

Write

Yes

text/csv

org.apache.wink.common.model.csv.CsvSerializer,
org.apache.wink.common.model.csv.CsvTable,
org.apache.wink.common.model.csv.MultiCsvTable

Not required. Registered by default

Examples

Producing CSV
@GET
@Produces("text/csv")
public CsvTable getJohns() {
    CsvTable cvs = new CsvTable("Id", "First Name", "Last Name", "Email");
    cvs.addRow("1","John","Kennedy","john@Kennedy.org");
    cvs.addRow("2","John","Lennon","john@Lennon.org");
    cvs.addRow("3","John","Malkovich","john@malkovich.org");
    cvs.addRow("4","John","McCain","john@McCain.org");
    return cvs;
}
Consuming CSV
@POST
@Consumes("text/csv")
public void postCsv(CsvTable csv) {
    for (String[] row : csv.getRows()) {
        for(String cell: row){
            System.out.print(cell + " ,");
        }
        System.out.print("\n");
    }
}
  • No labels