Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http message conversion not finding Jackson JDK8 module in context [SPR-13049] #17641

Closed
spring-projects-issues opened this issue May 19, 2015 · 6 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 19, 2015

John Franco opened SPR-13049 and commented

Despite having a Jackson JDK 8 module bean available in the context, deserializing a request having an Optional<String> field fails with an error indicating that the object mapper in use does not have the module installed. The attached git bundle has a maven project and a unit test to reproduce the problem. The unit test demonstrates that the object mapper available from the context does have the module installed (by deserializing a JSON string into an object having an Optional<String> field), which seems to indicate that the http message handling is using a different object mapper that doesn't have the module installed.


Affects: 4.1.6

Attachments:

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

We're only registering Jackson's general JDK 8 module by default as of Spring 4.2, so I suppose we're talking about a manually registered module here... with multiple ObjectMappers in use at runtime, and only one of them having the manual module registration applied?

Juergen

@spring-projects-issues
Copy link
Collaborator Author

John Franco commented

The code registers the module as a bean in the application context, which the documentation describes as a way to make the module available globally. I think the worse problem is that the object mapper in use by the MVC stack for deserializing requests is not picking up such globally-registered modules. Why doesn't the MVC stack just use the global object mapper bean? That seems the simplest way to let REST controllers customize their JSON handling.

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

ObjectMapper customization by providing a bean is the Spring Boot approach. Regular Spring MVC application, or Spring Boot applications using @EnableWebMvc should customize the message converters as described in this article.

Could you check what kind of web configuration your application is using?

@spring-projects-issues
Copy link
Collaborator Author

John Franco commented

Hello, thank you for responding. I've read the article and added a Jackson2ObjectMapperBuilder bean to the application context following the example at https://github.com/sdeleuze/spring-jackson-demo/blob/master/src/main/java/demo/Application.java. The deserialization still fails. I'll attach an updated git bundle. Would you prefer that I submit my code in another form?

The code is using annotation-driven configuration. The main class is ReproServerConfiguration.java in the git bundle.

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

I will have a look, thanks.

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

I had a look to your sample project, you are using @EnableWebMvc that disables Spring Boot Web autoconfiguration. Just remove @EnableWebMvc and your test will pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

2 participants