This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Skip to end of metadata
Go to start of metadata

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 org.apache.wink.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

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.

@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.

@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