JSON to Java POJO — Generate Java POJO Classes from JSON
Generate Java POJO classes from JSON with Jackson annotations. Immutable records, nullable fields, Lombok support — in your browser, no upload.
JSON to Java POJO
Convert JSON to Java POJO class with Jackson annotations. Works entirely in your browser.
Java has been the backbone of enterprise application development for decades, and its approach to JSON serialization is the most mature ecosystem in any language. Jackson, the de facto standard, can deserialize JSON into plain-old Java objects (POJOs) with zero configuration as long as the class structure matches the JSON shape — but the class structure still needs to exist. Hand-writing a Java class for every API response is a chore that scales linearly with the number of endpoints, and the generated class is the input to every downstream layer: the controller that returns it as JSON, the service that transforms it, the repository that persists it. The generator walks a JSON response, infers Java types, and emits a class that compiles directly into a project.
The non-obvious Java-specific concern is the choice between records and POJOs. Java records, introduced in Java 16, are a concise syntax for immutable data carriers: a one-line record User(String name, int age) is equivalent to a full POJO with a constructor, equals, hashCode, and toString. Jackson supports records natively through the @JsonCreator annotation on the canonical constructor. Records are the right default for new codebases on Java 16+ — they are shorter, safer, and express the intent (“this is a data object”) more clearly than a mutable POJO with setters. POJOs remain the right choice for codebases that need mutable state, frameworks that generate proxies (JPA, Spring AOP), or runtimes that predate Java 16.
The most common downstream step after generating a POJO is to plug it into a Spring Boot controller: annotate the class with @RestController, add a @GetMapping method that returns the POJO, and Jackson handles the serialization automatically. If the destination is a Kafka topic, add @Serde annotations or use Jackson’s ObjectMapper directly. The generated class is the data contract — the business logic that validates, transforms, and persists it is the part that belongs to the developer.
How to use
Paste your JSON
Drop a JSON object or array of objects into the input. The generator walks the structure and emits a Java class for the root, with nested static inner classes for each object shape.
Choose record or class style
Pick between Java 16+ records (immutable, compact constructor syntax) and traditional POJOs with private fields, getters, and setters. Toggle Jackson annotations for `@JsonProperty`, `@JsonIgnoreProperties`, and `@JsonCreator`.
Copy or download the .java file
Copy the generated Java to your clipboard or download as a .java file. The output compiles with `javac` and works with Jackson `ObjectMapper` — no extra import files needed.
Frequently asked
Should I choose records or POJOs?
Java records (Java 16+) are immutable by design and work well with Jackson's `@JsonCreator` for deserialization. Choose records if immutability is important and your project runs on Java 16 or later. Choose POJOs if you need mutable fields, setters, or compatibility with an older runtime.
How are JSON keys mapped to Java field names?
JSON keys in snake_case (`user_id`) become Java fields in camelCase (`userId`) by default, with a `@JsonProperty("user_id")` annotation preserving the original key for Jackson's `ObjectMapper`. Toggle off annotations to rely on Jackson's default property-naming-strategy.
How are nullable fields handled?
Fields that are null in the sample become `@Nullable` reference types. Primitives (`int`, `boolean`) are wrapped in their boxed types (`Integer`, `Boolean`) so they can hold null values. Add `@NotNull` or `@NonNull` annotations by hand if your API guarantees presence.
Does it generate Lombok annotations?
Yes — toggle 'Lombok' to emit `@Data`, `@NoArgsConstructor`, and `@AllArgsConstructor` annotations in place of manual getters and setters. The generated code is Java-clean either way; Lombok is a shortcut for codebases that already use it.
What about arrays and collections?
JSON arrays become `List<T>` fields. The generator emits `import java.util.List;` and uses the generic type for the list element. For typed collections, Jackson handles the deserialization automatically as long as the element type is a concrete class.
Limitations
- No JPA entity annotationsThe output is POJOs for JSON deserialization, not JPA entities for Hibernate. Add `@Entity`, `@Id`, and `@Column` annotations by hand if the class also maps to a database table.
- No enum detectionA string field that toggles between fixed values is emitted as String, not as a Java enum. Review the output and add `public enum Status { ACTIVE, PENDING, CLOSED }` by hand.
- Inferred types from a single sampleA field that is an integer in the sample but may be a decimal in other responses is typed as `int`. Review the output and widen to `double` or `BigDecimal` if your API is inconsistent.
Platform notes
- macOS
- IntelliJ IDEA, Eclipse, and VS Code with the Java extension pack all accept the generated classes. Use the browser tool for one-off generation during prototyping or when pasting from an API documentation page.
- Windows
- IntelliJ on Windows handles the generated class the same way. The browser tool is the right pick for quick one-off class generation without opening a full IDE.
- Linux
- For command-line work, `jsonschema2pojo` is the standard equivalent. The browser tool is the right pick for one-off generation where installing Maven or Gradle is not worth the setup time.
- Web
- Runs entirely client-side. Works offline once the page has loaded.