Comma Separated Values (CSV) Providers
Apache Wink supports the serializing and de-serializing of data as a CSV.
...
title | Reference |
---|
...
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 org.apache.wink.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 | Yes No | N text/A | N/A | |
Write | Yes | text/csv | CsvSerializer |
CsvDeserializerProvider
TBD
| Supported | Media Types | Entity |
---|---|---|---|
Read | Yes | text/csv | CsvDeserializer |
Write | No | N/A | N/A |
Comma Separated Values (CSV) Data Models
...
csv | org.apache.wink | Not required. Registered by default | ||
Write | Yes | text/csv | org.apache.wink | Not required. Registered by default |
Examples
The following code example demonstrates the reading and writing of CSV documents.
Producing CSV
The following code example demonstrates the creation of a CSV document.
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
The following code example demonstrates the consumption of a CSV document.
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");
}
}
|