0

I know how to get all the registered message converters, but is there a way to get the HttpMessageConverter for the request body of the current request, either in HandlerMethodArgumentResolver, RequestBodyAdviceAdapter or in the controller itself?

In RequestBodyAdviceAdapter you can get the type of the converter but not the instance itself.

Jaap van Hengstum
  • 4,494
  • 4
  • 30
  • 34
  • I want to get the Jackson ObjectMapper that was used to deserialize the JSON for the `@RequestBody` of the current request. Getting the default ObjectMapper in Spring Boot is probably right in 90% of cases, but in case a different message converter is used for a particular request I was wondering if I could get that ObjectMapper. – Jaap van Hengstum Jan 14 '16 at 15:13
  • That still doesn't answer the why :)... Why do you need that? You cannot (or should) reconfigure it as it is a singleton, if you want to do manual conversion just inject it. – M. Deinum Jan 14 '16 at 15:22
  • I'm writing a merge patch functionality in a rest controller and I'm parsing the JSON request to determine if `null` values in the request body object are present as null values in the JSON. Likely just an edge case but someone could add their own messageconverter and not use the default ObjectMapper. If this is not easy to do I'll just use the default ObjectMapper or optionally let the user plug in their own. – Jaap van Hengstum Jan 14 '16 at 15:36

0 Answers0