Generate Java classes from a JSON example — POJOs with getters/setters, Java 16+ records, or Lombok style. Nested objects become named classes; partially-present fields are boxed and documented.
Show calculation steps
Processed privately in your browser — nothing you paste is uploaded, logged or stored.
DTOs without the typing
Hand-writing Java classes for a deep API response is half an afternoon. Paste the JSON and choose a style: classic POJOs with getters and setters, compact Java 16+ records, or Lombok @Data. Nested objects become named classes (PascalCase, singularized from array keys — lines → Line), arrays become List<T>, and fields that are missing from some sample records are boxed and documented as possibly-null in a field-notes comment.
Worked example (record style)
public record Customer(String name, String email) {}
public record Line(String sku, long qty, String note) {}
public record Invoice(long id, String title, boolean paid,
double total, Customer customer, List<Line> lines) {}When to use it
- Typing third-party API responses for Jackson or Gson mapping.
- Bootstrapping DTO layers in new services from real payloads.
- Generating fixture classes for integration tests.
Limitations to know
- Whole numbers map to long, decimals to double — deliberately wide, since JSON declares no bit-widths; narrow manually where you know better.
- snake_case keys become camelCase fields with a note; add @JsonProperty/@SerializedName or a global naming strategy for those.
- One sample cannot reveal every optional field — feed the most complete example you have.
Related workflow
- Same sample, different target: the C# converter and TypeScript converter share the same shape inference, so multi-platform DTOs stay consistent.
How to use the JSON to Java Class Converter
- Paste a JSON example — an API response works best.
- Set the root class name and pick a style: POJO, record, or Lombok.
- Click "Generate Java".
- Review the field notes and paste the classes into your project.
Frequently asked questions
What Java types do JSON values map to?
Whole numbers → long, decimals → double, strings → String, booleans → boolean, arrays → List<T>, nested objects → generated classes. Optional fields (missing from some sample records) become boxed types (Long, Double, Boolean) so they can be null.
POJO, record or Lombok — which should I pick?
Records (Java 16+) for immutable DTOs — one line per class, ideal for API responses. POJOs when frameworks need setters or you are below Java 16. Lombok if your project already uses it — @Data generates the boilerplate at compile time.
Do the classes work with Jackson or Gson?
Yes for standard field names — both libraries map by name. Snake_case JSON keys become camelCase fields with a note; add @JsonProperty (Jackson) or @SerializedName (Gson) for those, or configure a global naming strategy.
Why long and double instead of int and float?
Safety at zero cost: JSON does not declare bit-widths, and a value that fits int today may not tomorrow. long and double cover the full range of what JSON numbers can hold in practice. Narrow them manually where you know better.