JSON to Java POJO
Generate Jackson-annotated Java POJOs from a JSON object
About JSON to Java POJO
Generates Java classes with private fields, getters, setters and Jackson @JsonProperty annotations from a JSON sample, starting with Root and adding a class for each nested object. Whole numbers map to int, decimals to double, null to Object and empty arrays to List<Object>. Each class is printed with its own imports, ready to save as a separate .java file, since Java allows only one public class per file.
Category: Converters.
Frequently asked questions
What is a POJO?
▾
A Plain Old Java Object (POJO) is a simple Java class with private fields and public getters/setters, with no dependency on a specific framework.
Which library are the annotations from?
▾
Jackson. The generated import is com.fasterxml.jackson.annotation.JsonProperty; add jackson-databind (group com.fasterxml.jackson.core) to your pom.xml or build.gradle, which brings in jackson-annotations and the ObjectMapper.
How are arrays handled?
▾
Arrays become java.util.List fields typed from their first element, so an array of objects gets its own class, as in List<Items>, and an empty array becomes List<Object>. Java generics can't hold primitives, so if a list of numbers or booleans comes out as List<int>, change it to List<Integer>, List<Double> or List<Boolean>.
How do I deserialize JSON with Jackson?
▾
ObjectMapper mapper = new ObjectMapper(); Root root = mapper.readValue(jsonString, Root.class); — the generated @JsonProperty annotations handle key mapping.