Json to Java object conversion

Let’s say you have rest service that posts some data to your server. The rest services uses JSON format to send data, but your server might not understand the JSON, therefore you will need to convert the JSON to Java object. Below is the sample of such service:

 

[code language=”java”]
@POST
@Path("/statistics")
@Consumes(APPLICATION_JSON_UTF8)
public Response getStatistics(String json)
throws JsonGenerationException,
JsonMappingException,

IOException {

ObjectMapper mapper = new ObjectMapper();

SomeCustomerTO someUser = mapper.readValue(json, SomeCustomerTO .class);
return null;
}
[/code]

Always good idea to include some logging to see if you receiving the correct json

Leave a Reply

Your email address will not be published. Required fields are marked *