Wildfly using the Jackson provider instead of Jettison

北城以北 提交于 2019-12-10 11:53:26

问题


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?

来源:https://stackoverflow.com/questions/19502878/wildfly-using-the-jackson-provider-instead-of-jettison

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!