Wildfly using the Jackson provider instead of Jett

2019-06-11 14:24发布

问题:

I've been using JBoss since version 4.3, I'm currently putting together a dimple demo webapp using Wildfly Beta1, CDI, JPA and RESTeasy, but I can't get to configure the JSON provider like I use to do in my other JBossAS projects...

I added a custom ContextResolver object to my project to correctly configure the JSON producer to serialize dates as ISO-8601 strings:

package org.demo.config;

import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;

import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;

@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonConfig implements ContextResolver<ObjectMapper>
{
    private final ObjectMapper mapper = new ObjectMapper();

    public JacksonConfig()
    {
        mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
    }

    @Override
    public ObjectMapper getContext(Class<?> objectType)
    {
        return mapper;
    }
}

And I added a jboss-deployment-structure.xml file to my deployment META-INF folder with the configuration I'm using in my other JBoss 7.X projects:

<jboss-deployment-structure xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="urn:jboss:deployment-structure:1.1 urn:jboss:deployment-structure:1.1 ">
  <deployment>
    <exclusions>
      <module name="org.jboss.resteasy.resteasy-jettison-provider" />
    </exclusions>
    <dependencies>
      <module name="org.jboss.resteasy.resteasy-jackson-provider" />
    </dependencies>
  </deployment>
</jboss-deployment-structure>

ANy thoughts?