Saturday, February 06, 2016

java.lang.String out of START_OBJECT token

If you are developing new spring rest services and encounter the following issue


Feb 06, 2016 10:17:05 AM org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleHttpMessageNotReadable
WARNING: Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not deserialize instance of java.lang.String out of START_OBJECT token
 at [Source: java.io.PushbackInputStream@353e55b8; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token

 at [Source: java.io.PushbackInputStream@353e55b8; line: 1, column: 1]


{
   "user": {
      "organizationId": 1,
      "roleId": 1,
      "statusId": 2,
      "email": "test@test.com,
      "password": "admin"
   },
   "person": {
      "firstName": "",
      "lastName": "",
      "phone": "",
      "mobile": ""
   }
}


The resolutions could be:

  • Your JSON request is invalid, check if it is complete and correct. 
  • You configured the spring mvc correctly.
  • You have required POM depedencies configured.
  • Your annotations are correct. @RequestBody is an important tag. 

               @RequestMapping(method = RequestMethod.POST,value = "/test")
  • public Response testData(@RequestBody TestData request){
    Response response = Response.positiveResponse();
    return response;
    }

No comments: