Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2016-07-26
3
Medium Priority
?
67 Views
Last Modified: 2016-08-09
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
0
Comment
Question by:Rohit Bajaj
2 Comments
 
LVL 16

Accepted Solution

by:
gurpsbassi earned 1000 total points
ID: 41729905
could try turning up the logging level.
0
 
LVL 36

Assisted Solution

by:mccarl
mccarl earned 1000 total points
ID: 41730518
Want to confirm if this is correct with experts.

Essentially correct, yes. There are a few added things like even after a Converter is matched on media type, it can still have a say as to whether it will perform the conversion or not (check the canRead, canWrite methods)

Note, there is also a MappingJacksonHttpMessageConverter (note it doesn't have the 2) that depending on your version of Jackson that you're using, this one may be getting used.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question