Skip to content
Advertisement

Using spring converter in @RequestBody

Is it possible to enforce Converter ( org.springframework.core.convert.converter.Converter) to finish json object mapping?

Json code example:

JavaScript

where somename – string, id – integer value

mapping to :

JavaScript

Converter code example:

JavaScript

What I want to achieve is to map that json to the object which will have automatically fetched from db nested object.

Advertisement

Answer

You should implement your own JacksonCustomMapper, by extending JsonMapper and then registering it into the set of HttpMessageConverters. But, I do not recommend to pollute the default conversion, you could pass in the @RequestBody an incomplete json and Jackson will parse it to your object, it would be sufficient to not pass wrong keys in your json object… An example (among thousands) here: http://magicmonster.com/kb/prg/java/spring/webmvc/jackson_custom.html. Enjoy it 🙂

Advertisement