users@jersey.java.net

[Jersey] Re: Tomcat servlet: MessageBodyWriter not found for media type=application/json

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 22 Aug 2013 09:32:47 +0200

Hi Guy,

Your resource config should work just fine, you only need to have it used actually to configure your Jersey application
(as opposed to creating it and forgetting in a static block somewhere). If you struggle to make this work,
please provide some more details on your application configuration.

HTH,

~Jakub

On Jul 4, 2013, at 1:15 AM, Guy Rouillier <guy.rouillier_at_gmail.com> wrote:

> I have a working Jersey 1.x servlet, and I'm just starting my first 2.0 servlet. Deployment platform is Tomcat 7. The resources are annotated to return either XML or JSON. I'm trying Jackson, and using JAXB annotations - nothing fancy.
>
> XML returns are working fine. When I attempt to get JSON, I get:
> org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class xxxxxxxxx, genericType=class xxxxxxxxx
> at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:191)
>
> I ran the json-jackson example, and I'm using the same JARs that it is using. I found this discussion on StackOverflow: http://stackoverflow.com/questions/5161466/how-do-i-use-the-jersey-json-pojo-support and followed the suggestion to add org.codehaus.jackson.jaxrs to jersey.config.server.provider.packages. This works!
>
> However, I can't find this suggestion anywhere in the documentation, so I'm assuming this is not the correct solution. I'm guessing I'm not registering the Jackson feature properly. I tried this:
>
> static {
> new ResourceConfig()
> .packages("com.mycompany.mypackage")
> .register(JacksonFeature.class);
> }
>
> But this didn't help. Any ideas?
>
> Thanks.
>
> --
> Guy Rouillier