This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Web Services and the fly likes Jersey REST -(Un)Marshaller Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Jersey REST -(Un)Marshaller" Watch "Jersey REST -(Un)Marshaller" New topic

Jersey REST -(Un)Marshaller

Jairo Novak

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

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,
I agree. Here's the link:
subject: Jersey REST -(Un)Marshaller
It's not a secret anymore!