Glassfish 4.1 : Replace default ( Moxy ) JSON-Binding Provider by Jackson 2.5.1

I switched from GlassFish 3.1.2 to GlassFish 4.1. for my project. I got some unexpected result while producing JSON since GlassFish 4.1 using Moxy as New Default JSON-Binding Provider instead of Jackson which is default for GlassFish 3.1.2. So I decided to use latest Jackson 2.5 for GlassFish 4.1 as default JSON-Binding Provider.

1.You need to register org.glassfish.jersey.jackson.JacksonFeature in your application if you want to use Jackson as your JSON provider. (by registering this, MOXy will be disabled).
Please check below code for registering JacksonFeature.

import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.glassfish.jersey.jackson.JacksonFeature;

public class MyApplication extends Application{

	private Logger LOGGER = Logger.getLogger(this.getClass().getName());
	public Set<Class<?>> getClasses() 
		final Set<Class<?>> classes = new HashSet<>(); 
		// register root resource 
                // register JacksonFeature so that glassfish will use jackson instead of moxy.
		}catch(Exception e)
			LOGGER.log(Level.SEVERE,"MyApplication : Jackson library not added.",e);
		return classes; 

2. Add below jars in GlassFish’s module folder i.e “HOME/glassfish4/glassfish/modules”
– jackson-annotations-2.5.1.jar
– jackson-core-2.5.1.jar
– jackson-databind-2.5.1.jar
– jackson-module-jaxb-annotations-2.5.1.jar
– jackson-jaxrs-base-2.5.1.jar
– jackson-jaxrs-json-provider-2.5.1.jar

3. Don’t forget to restart server 🙂 Now your GlassFish 4.1 is ready to use jackson.

Happy Coding 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s