users@jersey.java.net

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

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Thu, 19 Dec 2013 12:34:11 +0100

A very first few sentences from the linked documentation:

Jersey JSON support comes as a set of extension modules where each of these modules contains an implementation of a Feature that needs to be registered into your Configurableinstance (client/server). There are multiple frameworks that provide support for JSON processing and/or JSON-to-Java binding. The modules listed bellow provide support for JSON representations by integrating the individual JSON frameworks into Jersey. ...

Further documentation section describe details how to enable JSON support with MOXy (8.1.2), JSON-P (8.1.3), Jackson (8.1.4) or Jettison (8.1.5). So, your problem is that you are not registering any of the features. Please select an extension module of your choice and follow the user guide to register the feature (as needed).

HTH,
Marek


On 19 Dec 2013, at 08:20, ayaskant swain <ayas_swain_at_yahoo.com> wrote:

> 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
> <Student.java><StudentInfoClient.java><StudentInfoService.java><web.xml>