users@jersey.java.net

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

From: Guy Rouillier <guy.rouillier_at_gmail.com>
Date: Wed, 03 Jul 2013 19:15:21 -0400

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