Which maven artifact should I depend on for replacing jackson-jaxrs-json-provider?

462 views Asked by At

I'm planning to replace jackson-jaxrs-json-provider with MOXy thing. I tried to comment on MOXy is the New Default JSON-Binding Provider in GlassFish 4 and had no luck.

My stack is as follows.

Jersey
Spring
MyBatis

I'm using jackson-jaxrs-json-provider and providing a custom ContextResolver.

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

    public ObjectMapperContextResolver() {
        super();
        objectMapper = new ObjectMapper()
            .configure(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME, true);
        objectMapper.registerModule(new JaxbAnnotationModule());
    }

    @Override
    public ObjectMapper getContext(final Class<?> type) {
        return objectMapper;
    }

    private final ObjectMapper objectMapper;
}

My questions are

  1. which maven artifact should I depend on for replacing jackson-jaxrs-json-provider? Is it com.eclipsesource.jaxrs:provider-moxy?
  2. Is it the right way to work as described in above link? Note that my module is not for full featured AS, but for Tomcat.
1

There are 1 answers

0
Paul Samsotha On BEST ANSWER
  1. Which maven artifact should I depend on for replacing jackson-jaxrs-json-provide? Is it com.eclipsesource.jaxrs:provider-moxy?

You should be using

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-moxy</artifactId>
    <version>${jersey.version}</version>
</dependency>
  1. Is it the right way to work as described in above link? Note that my module is not for full featured AS, but for Tomcat.

Not really sure what you're asking here, but the jersey-media-moxy artifact doesn't use/depend on Jackson. So your use of ObjectMapper would not work. ContextResolvers with MOXy (JSON), would consist of using MoxyJsonConfig.

For other configurations of this artifact, the link you provided is a good place, and also The Jersey User Guide for working with MOXy