So, here's the provider class:
@Provider public class ObjectMapperProvider implements ContextResolver<ObjectMapper> { private ObjectMapper objectMapper; public ObjectMapperProvider() { objectMapper = new ObjectMapper(); objectMapper.configure(SerializationConfig.Feature.AUTO_DETECT_GETTERS, false); objectMapper.configure(SerializationConfig.Feature.AUTO_DETECT_IS_GETTERS, false); } @Override public ObjectMapper getContext(Class type) { return objectMapper; } }Note: I've also disabled the AUTO_DETECT_IS_GETTERS feature to prevent boolean is* methods from being auto-detected.
The provider class must be made known to Jackson. One way is to place it in one of Jackson's search packages, that is, in one the (sub)packages specified in the com.sun.jersey.config.property.packages parameter. See this post for more details.
No comments:
Post a Comment