In our jersey project, we are using 2 json providers, Moxy and Jackson. I want to know which provider is being used to deserialize my payload, whether its Moxy or Jackosn. Is there any way to find it?
Asked
Active
Viewed 579 times
1 Answers
1
There are ways to find it, but it unnecessary, as generally, the same one will be used. The way Jersey (2.x) is set up, is that MOXy (jersey-media-moxy
) is the default provider. If you have both on the classpath, without any further configuration, MOXy will be used.
There are a couple of ways to disable MOXy. Either explicitly register the JacksonFeature
(that comes with jersey-media-json-jackson
), or set the property ServerProperties.MOXY_JSON_FEATURE_DISABLE
to true
But just for completeness, the couple ways I can think of top of my head to figure out which one is being used
- Trigger an exception and handle it in a mapper. Check the stack trace. (I know not very elegant)
- Write a
ContextResolver
for theObjectMapper
. If Jackson is being used, thegetContext
method will be called (just add an s.o.p). See here - You could retrieve the provider through the injectable
Providers
interface. See here
There are probably other ways, but like I said, it doesn't really seem necessary. You should already know.

Community
- 1
- 1

Paul Samsotha
- 205,037
- 37
- 486
- 720