Reputation: 186
i am using Jersey 2.17, JSON and automatic feature discovery.
I have my custom JSON Provider extending JacksonJsonProvider
. It's annotated with @Provider
and automatically registerd, same as default one that comes with:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
I want to disable/exclude default one without giving up on feature scanning/manually registering everything.
Only solution I've came up with is @Priority(Integer.MAX_VALUE)
to make sure my provider have higher priority, but I don't like the idea of relying on priority.
tried jersey.config.disableJsonProcessing
but it does not seem to change anything
Upvotes: 6
Views: 3963
Reputation: 209112
Yeah, so the Jackson feature is wrapped in an auto-discoverable, so it's automatically registered. There a a couple options I see.
Disable the auto discovery feature with the property
CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE
- or -
"jersey.config.disableAutoDiscovery"
The only thing with this is that any other feature that you would expect to be registered automatically (which are also auto discovered) will need to be registered again. (There aren't many features that are auto-discovered, so it might not be that big of a problem to disable it, if any).
Not use jersey-media-json-jackson
and instead use
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.5.0</version>
</dependency>
jersey-media-json-jackson
actually uses that provider, it doesn't actually provide any of it's own Jackson functionality. All it does really is register the MBR, MBW, and ExceptionMapper, and also wrap it in the auto-discoverable. The JacksonJsonProvider
or JacksonJaxbJsonProvider
you extended is there. You may also want to register the JsonParseExceptionMapper
and JsonMappingExceptionMapper
.
Not sure why you are extending the JacksonJsonProvider
, but if it's just to register your own ObjectMapper
, the more common approach is to configure it in a ContextResolver
Upvotes: 6