JSON to Java Class
Generate a Java POJO or Lombok-styled model from a JSON object.
JSON to Java POJO & Lombok Model Generator
A POJO (Plain Old Java Object) is a simple class with private fields and public getters/setters. This generator infers types from your JSON: boolean for booleans, int/double for numbers, String for strings, List<T> for arrays, and a nested class for objects.
Enable Lombok annotations to significantly reduce boilerplate code by using `@Data`, `@Builder` (builder pattern design), `@NoArgsConstructor`, and `@AllArgsConstructor`. Use the Package Mapping panel to prepend package definitions, define custom import lists, and choose whether to generate nested JSON objects as static inner classes or standalone files.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Generating a POJO from a sample response rather than typing accessors.
- Getting boilerplate accessors written rather than hand-typing them for every field.
- Getting getters, setters and toString written for you.
- Seeing how nested objects map onto separate classes.
- Producing a POJO a serialisation library can bind without extra configuration.
Frequently Asked Questions
- How are Java types chosen?
- Strings map to `String`, booleans to `boolean`, whole numbers to `int` and fractional ones to `double`. A `null` becomes `Object`, because JSON gives no other clue about what the field would hold when populated.
- Why does a list of ints become List<Integer>?
- Java generics cannot hold primitives — `List<int>` does not compile — so the element type is always the boxed form. The field type itself stays primitive where it can, which is why `int count` and `List<Integer> counts` appear side by side.
- How is an array's element type decided?
- From every element, not just the first. A leading `null` used to decide the whole list, and `[1, 2.5]` claimed `List<Integer>`; now any fractional member widens the lot to `Double`, which is what Java would require anyway.
- What happens with an array of objects?
- The elements are merged before the class is generated, so a key present on only some of them still gets a field. Generating from the first element alone produced code that failed to compile the moment a later object had an extra key.
- What do the Lombok options change?
- `@Data` replaces the generated getters and setters, `@Builder` adds a fluent builder, and the constructor annotations replace the explicit constructors. Turning Lombok off emits a plain POJO that compiles with no extra dependency.
- Should nested types be inner classes or separate files?
- Inner classes keep a one-file paste convenient and are fine for DTOs used in one place. Separate top-level classes are better when a nested type is shared, since an inner class cannot be imported independently of its outer class.
Common errors and gotchas
- Using primitives where a field can be absent, since a primitive cannot represent null.
- Letting a whole number become `int` when another response returns a larger value.
- Assuming a serialisation library maps names automatically, when snake_case keys need annotations.
- Generating mutable setters where the model should have been immutable.
- Omitting equals and hashCode, which matters the moment the object goes in a collection.