Parsing JSON request body with Spring MVC -


I am using the Spring 4.1 framework to develop webservices. When I return a Java object as a response, it automatically gets converted to JSON and given to the customer, so I think the JSON parser is in orbit and it is configured correctly. However, it fails to convert the request body from JSON to Java object and the customer is getting an HTMT response of 400.

Here is how the webservice looks:

  public class details {public details () {} int code; Int area; } @RequestMapping (value = "/ api / update / {phoneNumber}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) Public ResponseEntity & lt; String & gt;  

How it looks like:

  Method: Post content-type: application / json; Charset = utf-8 body: {"code": 0, "field": 12}  

If I gather the requested body as a string and parse it manually So it works, so it becomes valid JSON, but for some reason it does not automatically parse, I have no clue about how to fix it. Please help. Thanks in advance.

You have package-personal properties in your description category, so they Probably not recognized by JSN-converter.

You have several options:

  • Define them publicly (not recommended)
  • Provide gates and senders
  • < Li> If you are using Jackson, you can annotate them with @Jesanproperty , leaving them package-private

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -