Force Glassfish4 uses Jackson instead of Moxy

Glassfish4 uses Moxy to serialize REST responses in JSON. Does anyone know how to configure the app to use Jackson instead of Moxy?

+12
jackson jersey glassfish moxy
source share
2 answers

You need to register JacksonFeature in your application if you want to use Jackson as your JSON provider (by registering this function, you will disable MOXy as your JSON provider).

You can do this either in a subclass of Application :

 public class MyApplication extends Application { public Set<Class<?>> getClasses() { final Set<Class<?>> classes = new HashSet<Class<?>>(); // Add root resources. classes.add(HelloWorldResource.class); // Add JacksonFeature. classes.add(JacksonFeature.class); return classes; } } 

or in ResourceConfig :

 final Application application = new ResourceConfig() .packages("org.glassfish.jersey.examples.jackson") .register(MyObjectMapperProvider.class) // No need to register this provider if no special configuration is required. // Register JacksonFeature. .register(JacksonFeature.class); 

See the Jackson Section in the Jersey User Guide for more information.

+15
source share

Michal Gaidos answered correctly, just to add this, add this dependency to your pom.xml,

 <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> <version>2.26</version> </dependency> 
+4
source share

All Articles