“如何在Wildfly中配置Jackson及其序列化功能?”
你不需要在Wildfly中进行配置,可以在JAX-RS应用程序中进行配置。只需使用
ContextResolver即可配置即可
ObjectMapper(请参阅此处的更多信息)。就像是
@Providerpublic class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> { private final ObjectMapper mapper; public ObjectMapperContextResolver() { mapper = new ObjectMapper(); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); } @Override public ObjectMapper getContext(Class<?> type) { return mapper; }}如果你还没有Jackson依赖项,则需要它,就像编译时依赖项一样
<dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jackson-provider</artifactId> <version>3.0.8.Final</version> <scope>provided</scope></dependency>
如果使用扫描来发现资源类和提供者类,ContextResolver则应自动发现它们。如果你明确注册了所有资源和提供程序,则还需要注册该资源和提供程序。它应该注册为单例。
更新
正如@KozProv在评论中提到的,它实际上应该
resteasy-jackson2-provider作为Maven依赖项的artifactId。
-jackson-使用旧版本
org.prehaus(Jackson 1.x),而
-jackson2-使用新版本
com.fasterxml(Jackson 2.x)。默认情况下,Wildfly使用The Jackson 2版本。



