Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2016-07-26
3
Medium Priority
?
65 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

618 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