Avatar of Rohit Bajaj
Rohit Bajaj
Flag for India asked on

How does spring convert a Json string that is being passed to an object

Hi,
I am making the following post request : http://localhost:8080/api/users/create
with postman and body :
{ "userName" : "rohit", "email" : "rohit@xyz.com" }

In my controller i have :
@RequestMapping(value = "/api/users/create", method = RequestMethod.POST)
    @ResponseBody
    public APIPOSTResponse userAdd(@RequestBody User user)

And this perfectly converts json to the User object.
I read in docs that spring using a HttpMessageConverters for this.
When i navigated from intellij to MessageConverter interface i saw many classes implementing it.
They were all in spring-web jar.
I found one implementation which i suspected : MappingJackson2HttpMessageConverter will do the conversion and put break points in the decompiled source code the debugger didnt stop. Although it did stop
in the class AbstractHttpMessageConverter.
My understanding is based on the mediaType proper converter will be invoked. Want to confirm if this is correct with experts. Also what converter is executed for mediaType application/json ?

Thanks
JavaJava EE

Avatar of undefined
Last Comment
mccarl

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
gurpsbassi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
mccarl

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes