...
Apache Wink provides a set providers that are capable of serializing a number of data models into JSON representations. There are currently 3 Apache Wink extensions that provide JSON support. Each has unique features that may make one more suitable for your particular application.
wink-json-provider (org.json)
The wink-json-provider extension is provided in the binary distribution and uses the JSON.org classes to provide JSON support. Include the wink-json-provider-<VERSION>.jar in the classpath and the providers will automatically be registered. You will also need the org.json JAR which is provided in the ext/wink-json-provider/lib folder.
...
| Supported | Media Types | Entity |
---|---|---|---|
Read | Yes | application/json , application/javascript | JAXB object, |
Write | Yes | application/json , application/javascript | JAXB object, |
Examples
Producing and Consuming JSON
Code Block |
---|
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject postJSON(JSONObject requestJSON) {
String property = requestJSON.getString("property");
JSONObject jobj = new JSONObject();
return jobj;
}
/* Book is a JAXB annotated class */
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Book postJSONBook(Book requestBookEntity) {
String title = requestBookEntity.getTitle();
/* other code */
Book response = new Book();
return response;
}
|
wink-jettison-provider (org.codehaus.jettison)
The wink-jettison-provider extension is provided in the binary distribution and uses the Jettison code to provide JSON support. Include the wink-jettison-provider-<VERSION>.jar in the classpath and the providers will automatically be registered. You will also need the Jettison library JARs which are provided in the ext/wink-jettison-provider/lib folder.
...
| Supported | Media Types | Entity |
---|---|---|---|
Read | Yes | application/json | JAXB object |
Write | Yes | application/json | JAXB object |
Example
Producing and Consuming JSON
Code Block |
---|
/* Book is a JAXB annotated class */
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Book postJSONBook(Book requestBookEntity) {
String title = requestBookEntity.getTitle();
/* other code */
Book response = new Book();
return response;
}
|
Jackson JSON Processor
Jackson JSON Processor may also suit your needs and can be used. They provide their own JAX-RS entity provider. See their documentation for more information.