dev@jersey.java.net

Getting MessageBodyWriter not found error while trying to send APPLICATION_JSON media type from JAX-RS Service using JAXB

From: ayaskant swain <ayas_swain_at_yahoo.com>
Date: Thu, 19 Dec 2013 14:38:41 +0800 (SGT)

Hi, 

I followed section 8.1.1.2 in the User Guide document of JAX-RS API at this link - https://jersey.java.net/nonav/documentation/latest/user-guide.html#d0e4883.

I have created a RESTful resource using JAX-RS API 2.0 & deployed in Tomcat 6.0.37. I want my service to return a Student object in JSON format to the REST client. The mapping of Java object (@XmlRootElement) should automatically be taken care by the underlying JAXB API.

But I am getting the below error on my server while trying to achieve this. 

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class com.ayas.rest.model.jaxb.Student, genericType=class com.ayas.rest.model.jaxb.Student.


I searched on google & found some suggestions to use a JACKSON library which will act as a provider for the JSON object. But nothing as such is written in the Jersey user guide link which I have posted above.

There is no issue when I am using MediaType as APPLICATION_XML. It is perfectly working fine & returning XML string. 

I am attaching my source code of both Server & client.  Please help.

Thanks
Ayaskant
Bangalore