M
M
mitaichik2019-02-26 18:22:58
Spring
mitaichik, 2019-02-26 18:22:58

How to do extra processing of @RequestBody?

Hello!
I have a regular controller where the @RequestBody object goes.
The problem is that this object has one property that comes with different methods (somewhere along with json, somewhere in the header, etc.). And now I want this property to be calculated and set before this object gets into the controller method.
Is it possible to configure Spring (Boot) so that after the object is returned by HttpMessageConverter, it is processed by an additional. object, and after that it got into the controller method?
There is, of course, an option - to process it in the right way in HttpMessageConverter, but I have several of them - I'll have to redo everything ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
al_gon, 2019-02-26
@al_gon

So not?

@Configuration
@EnableWebMvc
@ComponentScan
public class WebConfiguration extends WebMvcConfigurerAdapter {
 
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> httpMessageConverters) {
        httpMessageConverters.add(new MyCustomMessageConverter(new MediaType("json", "xml")));
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question