users@jersey.java.net

[Jersey] Re: JAXB and Jackson annotations together

From: Brian Mulholland <blmulholland_at_gmail.com>
Date: Thu, 5 Jul 2012 18:34:13 -0400

SOLVED

Eventually found this link:
http://stackoverflow.com/questions/5005668/configure-jersey-jackson-to-not-use-xmlelement-field-annotation-for-json-field

Which illustrates the exact solution which precisely solved my issue.
For posterity, it states that you should implement a class like the
following:

@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonContextResolver implements ContextResolver<ObjectMapper> {

    private ObjectMapper objectMapper;

    /**
     * Creates a new instance.
     *
     * @throws Exception
     */
    public JacksonContextResolver() throws Exception {
        this.objectMapper = new ObjectMapper().configure(
                DeserializationConfig.Feature.USE_ANNOTATIONS, false)
                .configure(SerializationConfig.Feature.USE_ANNOTATIONS, false);
        ;
    }

    /**
     * @see javax.ws.rs.ext.ContextResolver#getContext(java.lang.Class)
     */
    public ObjectMapper getContext(Class<?> objectType) {
        return objectMapper;
    }
}


And then reference as a singleton bean in your spring config.

<bean class="package.JacksonContextResolver" scope="singleton"/>


Brian Mulholland
"For every complex problem, there is an answer that is clear, simple and wrong."
--H.L. Mencken
"Politics is the art of looking for trouble, finding it everywhere,
diagnosing it incorrectly, and applying the wrong remedies."
--Groucho Marx