Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jersey REST -(Un)Marshaller  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

JsonExample example = (JsonExample) service.path("resources").path("res/1").accept(APPLICATION_JSON).get(JsonExample.class);


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,
Let's go to the waterfront with this tiny ad:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!