Skip to content

MappingJackson2(Http)MessageConverter should be more verbose in canRead/canWrite checks (on Jackson 2.3) [SPR-11261] #15886

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

Closed
spring-projects-issues opened this issue Dec 28, 2013 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 28, 2013

Oliver Drotbohm opened SPR-11261 and commented

The MappingJackson2HttpMessageConverter currently calls objectMapper.can(De)Serialize(…) to check whether the mapper supports a given type. The mapper returns false if it encounters an exception in the marshaling metadata setup. So if you have an error in your mapping setup, the HMC is not selected and you never find out why.

ObjectMapper has overloads for the can(De)Serialize(…) methods taking an AtomicReference to capture the issue that prevented the serializer from being able to (de)serialize the type. So it would be cool if we used those and log the reason in the debug level.


Affects: 3.2.6, 4.0 GA

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I've addressed this for both the web module and the messaging module variant of MappingJackson2(Http)MessageConverter, through a reflective check for the presence of Jackson 2.3. We're logging such exceptions at warn level, since they really shouldn't occur in a proper setup.

We're also building and testing against Jackson 2.3 now. However, I wonder why https://github.com/FasterXML/jackson doesn't mention 2.3 yet?

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Jan commented

Great feature.

How would I configure a RestTemplate that uses MappingJackson2HttpMessageConverter (for application/json) plus FooConverter (for application/foo), so that the jackson converter does not WARN in the logs when the returned resource is not json but shall be handled by the FooConverter?
Does it make sense in MappingJackson2HttpMessageConverter to check first the contentType and then the objectMapper.canSerialize() method?

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Apr 14, 2016

Juergen Hoeller commented

Following up to the last comment (sorry for not noticing it earlier): Checking the media type first has been addressed through #18735 in the meantime, already available in the latest 4.3 and 4.2.6 snapshots. Still working on fine-tuning the warn log in case of no media type specified.

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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants