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
- Host: GitHub
- URL: https://github.com/binout/jaxrs-csv
- Owner: binout
- License: apache-2.0
- Created: 2015-10-11T20:48:50.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-08T14:38:46.000Z (over 10 years ago)
- Last Synced: 2023-07-26T23:21:05.713Z (over 2 years ago)
- Topics: csv, java, jax-rs, jaxrs
- Language: Java
- Size: 24.4 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
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