Gradle Dependency

compile("com.fasterxml.jackson.core:jackson-databind:2.9.7")

POJO to JSON

ObjectMapper mapper = new ObjectMapper(); ObjectToMarshallType obj = new ObjectToMarshallType(); // Write JSON to file mapper.writeValue(new File("\path\to\file"), obj); // Object to JSON as String String jsonInString = mapper.writeValueAsString(obj);

JSON to POJO

The ObjectMapper can readValues from File, URL and "String Literals".

ObjectMapper mapper = new ObjectMapper(); // File to Object ObjectToMarshallType obj = mapper.readValue(new File("\path\to\in"), ObjectToMarshallType.class); // URL to Object ObjectToMarshallType obj = mapper.readValue(new URL("http://example.com/api/endpoint.json"), ObjectToMarshallType.class); // String Literal to Object ObjectToMarshallType obj = mapper.readValue( "{'key' : 'value'}", ObjectToMarshallType.class);

References

Going Further