Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Comma Separated Values (CSV) Providers

Apache Wink supports the serializing and de-serializing of data as a CSV.

...

titleReference

...

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.

CsvSerializerProvider

TBD

 

Supported

Media Types

Data Model

Provider registration Entity

Read

No

N/A

N/A

Write

Yes

text/csv

CsvSerializer

CsvDeserializerProvider

TBD

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

 

Supported

Media Types

Entity

Read

Yes

text/csv

CsvDeserializer

Write

No

N/A

N/A

Comma Separated Values (CSV) Data Models

...

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
Code Block

@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
Code Block

@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");
    }
}