Tuesday, 31 May 2016

How to convert Java Object to JSON string


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


ObjectMapper mapper  = new ObjectMapper();
TravelVo travelVo = new TravelVo();
                         travelVo.setDestination("Kashmir");
String jsonString = mapper.writeValueAsString(travelVo);

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.5</version>
</dependency>

No comments:

Post a Comment