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
@Path("/persons")
public class PersonResouce {
private static List<Person> repository = new ArrayList<>();
@GET
@Produces("text/csv")
public Response get() {
return Response.ok(repository).build();
}
@POST
@Consumes("text/csv")
public Response post(List<Person> persons) {
repository.addAll(persons);
return Response.ok().build();
}
}
CSV Schema configuration
-
Define order of CSV columns :
@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 :
@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)
@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
-