Skip to content
gohacks.dev
Tooling

JSON to Java Class Generator

Generate Java records or Jackson-annotated classes from a JSON sample, with nested types, List fields and @JsonProperty for keys that are not valid Java names.

Free · No sign-up · Your inputs stay in your browser

Input

Generate Java types from JSON

Output

Java

427 characters

Records are immutable and need Jackson 2.12 or later to deserialise. Whole numbers become Long and fractions Double, boxed so a missing value can be null. A key that is not a valid Java name keeps its JSON name through @JsonProperty. Types come from this one sample: give fields that are null here a real value to type them.

Runs in this browser. Nothing you paste is sent to a server.

Records or classes

Records (Java 16 and later) are immutable and need no getters, which suits data transfer objects; Jackson has deserialised them since 2.12. Classes with getters and setters are what older frameworks and JPA entities expect. Both outputs here compile against com.fasterxml.jackson.annotation and java.util.List.

Types to review

Long is chosen for every whole number because it never overflows where Integer might; narrow it if the API documents a smaller range. Money arrives as Double from a sample and belongs in BigDecimal, which Jackson reads when DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS is enabled or the field is declared BigDecimal.

Share

Frequently asked questions

Why are the generated fields boxed types like Long instead of long?
A primitive cannot be null, so a key that is missing or null in the JSON would silently become 0 or false. Boxed types keep that distinction; switch to primitives only for fields the API always sends.
How do I ignore unknown JSON properties?
Annotate the type with @JsonIgnoreProperties(ignoreUnknown = true), or configure the ObjectMapper with FAIL_ON_UNKNOWN_PROPERTIES disabled, so a new field in the API does not break deserialisation.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools