JSON to Java Classes Converter
Paste JSON to generate Java POJOs, Lombok classes, or Java Records. 100% client-side.
How to Convert JSON to Java Classes
- Paste your JSON into the input area on the left.
- Choose a mode — POJO (classic getters/setters), Lombok (annotation-driven), or Record (Java 16+ immutable).
- Copy or download the generated Java code using the buttons above the output.
- Add it to your project and use with Jackson or Gson to deserialize JSON at runtime.
Java JSON Libraries Overview
Java's most popular JSON libraries are Jackson and Gson. Jackson (com.fasterxml.jackson.core:jackson-databind) is the de facto standard, used by Spring Boot, Quarkus, and Micronaut. Gson (com.google.code.gson:gson) is Google's library, popular in Android development. Both work with the generated POJOs from this tool without additional configuration, assuming your JSON uses camelCase keys matching the Java getter/setter convention.
Output Modes Explained
- POJO — Classic Java class with private fields, public getters (
getName()), and public setters (setName(String name)). The JavaBeans standard. Compatible with all Java JSON libraries, XML frameworks, and Java EE/Jakarta EE. Best for maximum compatibility and projects without build-time annotation processing. - Lombok — Adds
@Data(generates getters, setters, equals, hashCode, toString),@NoArgsConstructor, and@AllArgsConstructor. Also adds@JsonDeserializefor Jackson compatibility. Requires Lombok on the classpath and IDE plugin installation. Dramatically reduces boilerplate — a 50-line POJO becomes 10 lines. - Record — Java 16+ record syntax. Records are immutable: fields are set at construction and cannot be changed. Accessor methods are generated automatically (no "get" prefix:
name()notgetName()). Jackson 2.12+ and Gson 2.10+ support records. Ideal for read-only API response models.
Java Type Mapping from JSON
- JSON string →
String - JSON integer →
int(primitive) orInteger(nullable) - JSON float →
double(primitive) orDouble(nullable) - JSON boolean →
boolean(primitive) orBoolean(nullable) - JSON null →
Object(use wrapper types for nullable primitives) - JSON array of strings →
List<String> - JSON array of objects →
List<ChildClass> - JSON nested object → separate class definition
Using Generated Classes with Jackson
Add Jackson to your Maven project: <dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId></dependency>. Then deserialize: ObjectMapper mapper = new ObjectMapper(); RootObject obj = mapper.readValue(jsonString, RootObject.class);. For arrays: List<RootObject> list = mapper.readValue(jsonString, new TypeReference<List<RootObject>>(){});. Spring Boot auto-configures an ObjectMapper bean — just use @RequestBody RootObject data in your controller.
Setting Up Lombok
Lombok requires annotation processing in your IDE and a build dependency. For Maven: add org.projectlombok:lombok with provided scope. For Gradle: use compileOnly 'org.projectlombok:lombok' and annotationProcessor 'org.projectlombok:lombok'. In IntelliJ IDEA: install the "Lombok" plugin from the marketplace. In Eclipse: run the Lombok installer jar. Once set up, the @Data annotation replaces all getter, setter, equals, and hashCode code with a single annotation.
Java Records and Immutability
Java Records guarantee immutability — once constructed, a record's fields cannot be changed. This makes records ideal for representing API responses that should not be mutated. The compact record syntax public record Person(String name, int age) is equivalent to a full class with a constructor, two final fields, two accessor methods, and implementations of equals, hashCode, and toString. Jackson supports records via the jackson-module-parameter-names module which reads constructor parameter names. Spring Boot 2.7+ includes this module automatically.
JSON to Java vs. Other Languages
Java's approach to JSON is more verbose than dynamic languages due to its static type system, but this verbosity provides compile-time safety and IDE support. Compared to Go's struct tags, Java requires no annotations by default when using camelCase — Jackson's default naming strategy matches JSON camelCase to Java camelCase fields. Compared to Python, Java requires more lines but gets type safety and IntelliSense in return. For a typed alternative with less boilerplate, see our JSON to Kotlin converter or the JSON to TypeScript converter for frontend work.