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:

 

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

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s