There is a service:

@RestController @RequestMapping("/generals") public class Manager { @RequestMapping(value = "/request", method = RequestMethod.POST) public ResponseEntity<String> createRequestFilter( HttpServletRequest request, @RequestBody String requestBody ) throws IOException { } } 

I send him a POST request with JSON. Type application\json .

I get the error:

 com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token 

that is, the request arrives, but falls on trying to cast Json into a String .
Tried to change from String to ObjectNode - it all started.
But, I would like to understand what's the matter.

  • What request comes to this URL? There is an assumption that you send a request: TestString , and the spring should be "TestString" - damintsew
  • {"user": {"bithday": "2016-09-12T08: 03: 13 + 00: 00"}, - Roberto
  • oh how Then the String will not work. Now I will write in response. And you add an example request to your question - damintsew

2 answers 2

You can create a separate class graph describing the input parameters:

 public class RootElement { private User; //getters and setters } public class User { @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-ddd'T'hh:mm:ss") private Date birthday; //getters and setters } 

Change in your controller:

 @RequestMapping(value = "/request", method = RequestMethod.POST) public ResponseEntity<String> createRequestFilter( HttpServletRequest request, @RequestBody RootElement requestBody 

    The issue was resolved by removing the interceptor added by accident to the spring context. He transformed the coming body.