我从4.3版开始就使用JBoss,我目前正在使用 Wildfly Beta1 , CDI , JPA 和 RESTeasy ,但我不能像我在其他JBossAS项目中那样配置JSON提供程序......
我在项目中添加了一个自定义ContextResolver
对象,以正确配置JSON生成器,将日期序列化为ISO-8601字符串:
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;
}
}
我在部署jboss-deployment-structure.xml
文件夹中添加了META-INF
文件,其中包含我在其他JBoss 7.X项目中使用的配置:
<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>
任何想法?