Bootstrap ObjectMapper not used in Jersey MessageBodyWriter
See original GitHub issueDropwizard’s bootstrap object has an ObjectMapper in it that we’ve been trying to get to understand java8 datatypes (Optional / DateTime / etc). Initially we thought the dropwizard-java8 bundle would do this for us, as it’s setting up bootstrap.getObjectMapper() with the appropriate jackson modules, and allows us to return Optional resources. However, in order to return objects that contain Optionals it appears we need to do the following in our Application’s run() method:
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(objectMapperWithAppropriateModules);
environment.jersey().register(provider);
It feels like a bug in dropwizard the the boostrap ObjectMapper is not being used by the reflection-instantiated JacksonJaxbJsonProvider? We’re seeing this behavior with Dropwizard 0.9.1 and dropwizard-java8 0.9.0-1
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
MessageBodyWriter not found for media type=application/json ...
I am using Jersey 2.8 Client to ...
Read more >Jersey 2.37 User Guide - GitHub Pages
This is user guide for Jersey 2.37. We are trying to keep it up to date as we add new features. When reading...
Read more >Configuring ObjectMapper DropWizard uses - Google Groups
Looking at code in DropWizard that creates Jackson ObjectMapper, I find that it is rather difficult to customize. Part of the problem is...
Read more >Customizing ObjectMapper in a JAX-RS application
If you use Jackson as the JSON provider in your JAX-RS application, you may want to redefine the default Jackson behaviour or even...
Read more >Jersey 2.4.1 User Guide
Default property values for MOXy MessageBodyReader<T> / MessageBodyWriter<T> . ... well as it does not contain a Main class that was used to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

FWIW, a work around is to turn auto discovery off:
environment.jersey().property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, Boolean.TRUE);This needs to be done for any jersey http clients you build, too:
(Incidentally, doesn’t everyone love double negative flags?)
Jersey rejected my request to allow inheriting: https://github.com/jersey/jersey/pull/221
Looking a little deeper, I am wondering why Dropwizard defines a
JacksonJaxbJsonProviderat all?It is currently being used to define the ObjectMapper to be used. From what I understand, Jersey recommends this to be defined through an ObjectMapperProvider, such as in this example: https://github.com/jersey/jersey/blob/2.23.1/examples/json-jackson/src/main/java/org/glassfish/jersey/examples/jackson/MyObjectMapperProvider.java
The JsonProvider is also adding support the
@JsonIgnoreTypeannotation. There may be another way to provide this as well.I would be happy to dig deeper into the possibility of replacing
JacksonMessageBodyProvideraltogether, if this would be of interest.