title

fire chief's random developer tidbits

Wednesday, June 1, 2011

Jersey JSON error after upgrading

We are stuck in the past with a lot of our libraries which causes headaches.  One example was that we were still using Jersey 1.0.3, which was causing problems when upgrading to Glassfish 3.1 from 2.1.  Upgrading all the project poms to Jersey 1.5 (which is bundled in Glassfish 3.1 at the moment, where 1.8 is almost done...) wasn't too bad, and I centralized the version number in the process.  The app deploys fine, but then we ran into this error:


javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class blah, and Java type class blah, and MIME media type application/json was not found

All it took to solve this problem was to add jersey-json to the dependencies:

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.5</version>
</dependency>

Credit to http://stackoverflow.com/questions/6027097/how-to-produce-json-output-with-jersey-1-6-using-jaxb