Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we still need JacksonFeature.class for Jersey 2.17 projects?

I have been trying to know if JacksonFeature.class is still needed for Jersey 2.17. I can't see any difference between the outputs between codes that JacksonFeature.class is registered or not.

Then, I forked a code from codingpedia codingpedia, removed JacksonFeature.class, upgraded to Spring 4.1.2 and jersey 2.17, updated the codes and the test still passed.

So I created a very simple web service to test this again github link, having in mind to remove all the moving parts and still worked. So do we still need to register JacksonFeature?

like image 643
Francis Zabala Avatar asked Mar 25 '15 04:03

Francis Zabala


1 Answers

Yeah I don't know why that tutorial they are using Jersey 2.9, but for the jersey-media-json-jackson artifact, they are using 2.4.1. Generally you should keep the Jersey (related artifact) versions the same. In the actual Github Project, the author changed this to use the project's ${jersey.version} (which is 2.14), which makes more sense.

But to answer your main concern, starting from version 2.9 the jersey-media-json-jackson module, takes part in the AutoDiscoverable classpath scanning, which involves Java's Service Provider mechanism. You can see this change by switching back and forth to the 2.8 version and and 2.9 (an upward) version of this module. You will see in the META-INF/services, the file org.glassfish.jersey.internal.spi.Autodiscoverable (which list the JacksonAutoDiscoverable implementation), in version 2.9 (and up). With this, the feature does not need to be explicitly configured, unless the the auto-discoverable feature is disabled (which is possible to explicitly do).


And just for completeness, when you have MOXy on the classpath, and you don't explicitly register the Jackson feature, MOXy will be used, as MOXy is the default provider. Even though you may not have a explicit dependency on MOXy, in situations like the case of using Glassfish server, it has the MOXy artifact, in which case we can either explicitly register the Jackson Feature, which automatically disables MOXy, or we can explicitly disable MOXy with the property ServerProperties.MOXY_JSON_FEATURE_DISABLE set to true

like image 191
Paul Samsotha Avatar answered Oct 08 '22 06:10

Paul Samsotha