Specify Message Converters for a Single Spring Controller

I am writing a postback handler library for a service that has some odd JSON matching methods. I can very easily configure a custom Jackson ObjectMapperto handle the mapping, but if I register the Spring MVC message converter with this mapper, it will apply the mapping (which is not true for the rest of the JSON I'm dealing with) to all incoming requests.

There are several manual approaches that I can use to manually decode these messages, but it would be much cleaner if the Spring type conversion service would handle it in the request pipeline.

Is there a possible way to connect a custom message converter to a specific controller, handler method, or display line / pattern / prefix?

+4
source share
1 answer

I had a similar situation - I wanted to create my own equivalent @ResponseBody, which would allow me to configure some aspects of JSON serialization (in my example, I wanted JSON values ​​to be optionally encoded html). I ended up creating a custom annotation @JsonResponseBodythat will force spring mvc to use Jackson's variously configured message converter for methods annotated with it.

spring AbstractMessageConverterMethodProcessor , CustomAbstractMessageConverterMethodProcessor spring, RequestMappingHandlerAdapter. , xml config, BeanPostProcessor.

, ( , spring 3.1), .

+1

Source: https://habr.com/ru/post/1539533/


All Articles