Reputation: 2207
I've the following code to change a property in Jackson. I'm annotating the classes with XMLRootElements and letting Jersey convert it to JSON, using jackson.
Classes are JAXB annotated.
@Provider
@Produces("application/json")
public class JacksonObjectMapper implements ContextResolver<ObjectMapper> {
private ObjectMapper objectMapper;
public JacksonObjectMapper() throws Exception {
objectMapper.configure( DeserializationConfig.Feature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
}
@Override
public ObjectMapper getContext(Class<?> type) {
return this.objectMapper;
}
}
The configuration above, works as expected if I use Jackson outside jersey (i.e: using his own function), but If I use it inside a Jersey app, the configuration options are ignored.
Is there a way to instruct Jersey to use my class to serialize / deserialize from XML to JSON?
Upvotes: 1
Views: 2208
Reputation: 37009
Add this class to your javax.ws.rs.core.Application's classes list:
application.addClass(JacksonObjectMapper.class)
Upvotes: 2