users@jersey.java.net

[Jersey] Getting MessageBodyWriter not found for media type=application/json Error

From: ayaskant swain <ayas_swain_at_yahoo.com>
Date: Thu, 19 Dec 2013 15:20:39 +0800 (SGT)

Hi, 

I followed section 8.1.1.2 (JAXB based JSON support)  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 service using JAX-RS API 2.0 & deployed in my Tomcat 6.0.37. I want my service to return a Student object in JSON format to the REST client. The mapping of Student Java object (Annotated with @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