Want to use Payara / Glassfish with JAX-RS and Jackson to serialize/deserialize objects to/from JSON? Pay extra attention as it might bite you as it had bit me.

I was more than sure that Payara is using Jackson as JSON processor (I’ve checked pom.xml dependencies of Payara and found that Jackson 2.5.1 is defined there). Therefore, I started using all those nice @JsonProperty or @JsonAutoDetect annotations while scratching my head why is Payara ignoring them but still did “some” serialization using some defaults, i.e. serialize only read-write properties (with getter and setter) and not fields, etc.

It occurs that by default Payara is using Eclipse MOXy and not Jackson.

Therefore, if you’d like to use Jackson annotations with JAX-RS on Payara the easiest way I found was to disable Eclipse MOXy directly in your Application subclass like below:

@ApplicationPath("resources")
public class JaxRsConfiguration extends Application {
   
    @Override
    public Map<String, Object> getProperties() {
        Map<String, Object> props = new HashMap<>();
    
        props.put("jersey.config.server.disableMoxyJson", true);
    
        return props;
    }
}

As an alternative, it’s also possible to turn on Jackson feature (sample solution can be found here.

However, I like the auto-discovery feature of all my REST resources as well as the Providers so I wanted something with less impact on my configuration.

Hence I ended up with setting jersey.config.server.disableMoxyJson property.