Friday, May 23, 2014

How to enable RestEasy in JBoss AS 7.1 to use Jackson processor

Problem 

The environment used is JBoss AS 7.1 which owns RestEasy (a framework to build RESTful webservices). JBoss by default uses RestEasy framework. I added the Jackson annotation @JsonSerialize (include=JsonSerialize.Inclusion.NON_NULL) on top of my REST model classes to filter the NULL fields from the JSON response during serialization. But, RestEasy ignored this Jackson annotation.

Solution

With reference to some forums in internet, I came to know the following. To enable Jackson processor for RestEasy, the below maven dependency and configuration need to be done. If not, RestEasy may use Jettison processor.

1. Maven Jackson dependency
<groupId>org.jboss.resteasy</groupId>  
      <artifactId>resteasy-jaxrs</artifactId>  
      <version>${version.jboss.resteasy}</version>  
      <scope>provided</scope>  
 </dependency>  
   
 <dependency>  
      <groupId>org.jboss.resteasy</groupId>  
      <artifactId>resteasy-jackson-provider</artifactId>  
      <version>${version.jboss.resteasy}</version>  
      <scope>provided</scope>  
 </dependency>  
2. Create a file under named "jboss-deployment-structure.xml" under the WEB-INF folder and include the jackson modules in the dependencies.
<? xml version= "1.0" encoding = "UTF-8"?>  
< jboss-deployment-structure>  
   <deployment >  
     < dependencies>  
       <!-- added the below jackson modules to enable JBoss RestEasy to  
       use Jackson -->  
       < module name= "org.codehaus.jackson.jackson-core-asl" />  
       < module name= "org.codehaus.jackson.jackson-mapper-asl" />  
     </ dependencies>  
   </deployment >  
 </ jboss-deployment-structure>  

2 comments:

Fabiano said...

Did it work for you?

Anonymous said...

No, it doesn't. :(