[jboss-dev-forums] [JBoss AS 7 Development] - Re: Resteasy jboss7 jackson configuration

Thomas Letsch do-not-reply at jboss.com
Thu Dec 8 06:22:08 EST 2011


Thomas Letsch [http://community.jboss.org/people/thomas.letsch] created the discussion

"Re: Resteasy jboss7 jackson configuration"

To view the discussion, visit: http://community.jboss.org/message/640537#640537

--------------------------------------------------------------
A late answer, but perhaps it solves someone else's day:

I have a customer jaxrs provider for my configuration:

{code} import java.text.SimpleDateFormat; import java.util.logging.Logger;  import javax.ws.rs.Consumes; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.ext.Provider;  import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.SerializationConfig; import org.codehaus.jackson.map.annotate.JsonSerialize; import org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProvider;  @Provider @Consumes({ MediaType.APPLICATION_JSON, "text/json" }) @Produces({ MediaType.APPLICATION_JSON, "text/json" }) public class JacksonConfigurator extends ResteasyJacksonProvider {      private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZ";      private static final Logger log = Logger.getLogger(JacksonConfigurator.class.getName());      public JacksonConfigurator() {         super();         log.info("configuring date handling");         ObjectMapper mapper = _mapperConfig.getConfiguredMapper();         configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);         configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);         SerializationConfig serConfig = mapper.getSerializationConfig();         serConfig.setDateFormat(new SimpleDateFormat(DATE_FORMAT));          serConfig.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);         DeserializationConfig deserializationConfig = mapper.getDeserializationConfig();         deserializationConfig.setDateFormat(new SimpleDateFormat(DATE_FORMAT));      }  } {code} 

Additionally I had to enable the folowing JBoss module dependencies in my war file: org.jboss.resteasy.resteasy-jackson-provider,org.codehaus.jackson.jackson-jaxrs,org.codehaus.jackson.jackson-mapper-asl,org.codehaus.jackson.jackson-core-asl
 That was all. On the first rest request, the mapper gets configured.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/640537#640537]

Start a new discussion in JBoss AS 7 Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-dev-forums/attachments/20111208/ffe6936c/attachment.html 


More information about the jboss-dev-forums mailing list