Upgrading Jersey with Spring, JAXB and Jackson 1.x to Jackson 2.x

A while ago we decided to upgrade Jackson from 1.x to 2.x (faster jackson). We were also using JAXB to map Java objects to JSON and Jersey for exposing our REST services and of course we wanted to retain those after the Jackson upgrade. The process is really quite easy once you’ve figured things out.

Maven dependencies

Before the update we depended on the following Jackson artifacts in Maven:

Where the jackson.version property was equal to 1.9.11. All of these dependencies could be replaced with:

Configuring web.xml

In order for Jersey to pick up the JAXB providers we have to configure the Jersey Spring Servlet to include the JAX-RS JSON package from Jackson 2:

The thing of interest here is the com.fasterxml.jackson.jaxrs.json package defined in the com.sun.jersey.config.property.packages Servlet parameter. This is what will make JAXB pojo mapping work.

That’s it!

This Post Has 2 Comments

  1. Thank you buddy, this was an awesome solution. I was missing the changes in the Web.xml and that made my code fail. It was not recognizing the @XMLELEMENT.. Thanks for putting this blog out there..Life Saver :)

  2. Yip, thanks!!!

Leave a Reply

Close Menu