| Author |
Jersey REST -(Un)Marshaller
|
Jairo Novak
Greenhorn
Joined: Mar 29, 2011
Posts: 2
|
|
Hello Java people,
I have done some tests with Jersey Framework and it seems to have nice future :-)
Nevertheless I have some questions.
I found out that when I use Jersey framework and its API for web server and also for client application I do not need to marshal or unmarshal data received/sent by GET/POST requests.
Is this true?
Example (JsonExample is JAXB annotated java class):
when I use
1.
JsonExample example = (JsonExample) service.path("resources").path("res/1").accept(APPLICATION_JSON).get(JsonExample.class);
or
2.
Class[] types = {JsonExample.class};
ClientResponse response = (ClientResponse)service.path("resources").path("res/1").accept(APPLICATION_JSON).get(ClientResponse.class);
String textEntityJson = (String)response.getEntity(String.class);
JSONJAXBContext contextj = new JSONJAXBContext(JSONConfiguration.natural().build(), types);
JSONUnmarshaller um = contextj.createJSONUnmarshaller();
JsonExample example = (JsonExample) um.unmarshalFromJSON(new StringReader(textEntityJson), JsonExample.class);
I have got the same JsonExample result.
A) Therefore my question is why or where (in which cases) do I have to use the JSON marshaller and unmarshaller approach?
B) And is it true that using Jersey, (un)marshalling is not necessary for GET and POST? I mean not needed to use JSONUnmarshaller or JSONMarshaller because Jersey does it automatically(?)
C) Did I understand it right,that annotated classes created from XSD file by xjc (including @XmlRootElement annotation) can be used for JSON and also for XML handling? I read that JAX-RS supports automatic maping from JAXB annotated class to XML and JSON.
Thanks a lot,
Jairo
|
 |
 |
|
|
subject: Jersey REST -(Un)Marshaller
|
|
|