An open API service indexing awesome lists of open source software.

https://github.com/binout/jaxrs-csv

A provider for text/csv media type
https://github.com/binout/jaxrs-csv

csv java jax-rs jaxrs

Last synced: 2 months ago
JSON representation

A provider for text/csv media type

Awesome Lists containing this project

README

          

= Jaxrs-csv

A JAX-RS provider to manage `text/csv` media type

== MessageBodyWriter/Reader

The project provides an instance of `MessageBodyReader` and `MessageBodyWriter` for `text/csv`.

=== Example of resource

[source, java]
----
@Path("/persons")
public class PersonResouce {

private static List repository = new ArrayList<>();

@GET
@Produces("text/csv")
public Response get() {
return Response.ok(repository).build();
}

@POST
@Consumes("text/csv")
public Response post(List persons) {
repository.addAll(persons);
return Response.ok().build();
}
}
----

== CSV Schema configuration

* Define order of CSV columns :

[source, java]
----
@CsvSchema(columns = { "firstName", "lastName", "age" })
public class Person {

private String firstName;
private String lastName;
private int age;
}
----

* Default CSV separator is : `;`. If you want to use another separator, you can override it :

[source, java]
----
@CsvSchema(separator=',',
columns = { "firstName", "lastName", "age" })
public class Person {

private String firstName;
private String lastName;
private int age;
}
----

* You can skip the first row during parsing (default is `false`).
Needed to support CSV-like file formats that include additional non-data content before real data begins)

[source, java]
----
@CsvSchema(separator=',',
columns = { "firstName", "lastName", "age" },
skipFirstDataRow = true)
public class Person {

private String firstName;
private String lastName;
private int age;
}
----

== TODO

* Configure CSV Schema
** header or not
** default value for `null` java value