Tuesday, 31 May 2016

How to Convert JSON value to Java Object




import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

try {
ObjectMapper mapper  = new ObjectMapper();
TravelVo travelVo = mapper.readValue(jsonValue, TravelVo.class);
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

Add the below dependency in pom
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.5</version>
</dependency>

No comments:

Post a Comment