Showing posts with label RESTful services. Show all posts
Showing posts with label RESTful services. Show all posts

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;
    }

Tuesday, December 30, 2008

RESTful web services

RESTful services are a nice way of integrating how the web interacts with Humans and Machines in the simplest format. Though developer community doesn't feel any pain in building standard web services using SOAP, WSDL over HTTP, there is lot of complexity behind implementing web services.

RESTful web services offer simplest solution, making same HTTP protocol used for web services as well.

There are 2 important aspects in RESTful services.

1. Web method
2. Scope

When we use standard web services, web service method name is very important. RESTful removes this overhead. Just use the standard HTTP GET, POST,PUT,DELETE etc methods for any transaction.


Scope of the request is similar to the query string logic of HTTP. Query string must be able to define the scope of a client request, on what he needs to be done.

I will post more about it as and when I get time.