Books

In Java, Play uses the Jackson JSON library to convert objects to and from JSON. Play’s actions work with the JsonNode type and the framework provides utility methods for conversion in the play.libs.Json API.

Jackson allows you to easily convert Java objects to JSON by looking at field names, getters and setters. As an example we’ll use the following simple Java object:

// Note: can use getters/setters as well; here we just use public fields directly.
// if using getters/setters, you can keep keep the fields `protected` or `private`
public static class Person {
public String firstName;
public String lastName;
public int age;
}

We can parse the JSON representation of the object and create a new Person: