question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bootstrap ObjectMapper not used in Jersey MessageBodyWriter

See original GitHub issue

Dropwizard’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:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

18reactions
RobeEWcommented, Oct 5, 2016

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:

new JerseyClientBuilder(environment)
            .withProperty(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, Boolean.TRUE)
            .build('main');

(Incidentally, doesn’t everyone love double negative flags?)

8reactions
oilliocommented, Jun 21, 2016

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 JacksonJaxbJsonProvider at 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 @JsonIgnoreType annotation. There may be another way to provide this as well.

I would be happy to dig deeper into the possibility of replacing JacksonMessageBodyProvider altogether, if this would be of interest.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found