About the JSON to Java Class tool
Mapping JSON to Java objects with Jackson or Gson requires a class for every object in the payload, with matching field names and getters and setters. For a real API response that can mean hundreds of lines of boilerplate. This JSON to Java generator writes them from a sample.
Choose classic POJOs with private fields plus getters and setters, or compact records for Java 16 and later. Field names are camelCase; when that differs from the JSON key, Jackson's @JsonProperty annotation keeps the mapping exact, and @JsonIgnoreProperties(ignoreUnknown = true) stops unknown fields from failing deserialisation. Integers become long, decimals double, booleans boolean and arrays List<T>. Values that can be null or missing use boxed types such as Long and Boolean.
All types are written into one file: the root class is public and the nested classes are package-private, so the file compiles as is. Nothing is uploaded; generation happens in your browser.
How to use JSON to Java Class
- Paste JSON into “JSON sample”, open a file, or click “Load sample”.
- Enter the “Root type name” and an optional “Package”.
- Choose “Declare as”: POJO with getters/setters or record (Java 16+).
- Toggle “Jackson annotations”.
- Copy the code or download it and save it as RootName.java.
Features
POJOs or records
Traditional JavaBeans or modern immutable records from the same JSON.
Jackson-ready
@JsonProperty for renamed keys and @JsonIgnoreProperties for forward compatibility.
Boxed types when nullable
Primitive types are used only where the sample never had null or a missing key.
Keyword-safe names
Keys such as class or default are renamed so the code compiles.
Single compilable file
One public root type plus package-private helpers in one .java file.
When to use it
- Create DTOs for a Spring Boot REST client.
- Model a JSON configuration loaded with Jackson's ObjectMapper.
- Build Android data classes for a Retrofit API.
- Generate records for event payloads in a Kafka consumer.
- Start a Java SDK for a public API from its example responses.
Frequently asked questions
Does it work with Gson?
Yes. Gson maps fields by name, so turn off Jackson annotations if the keys already match. For renamed fields, add Gson's @SerializedName.
Can I use Lombok?
Choose the POJO style, delete the getters and setters, and add @Data or @Getter/@Setter to each class.
Why are some fields Object?
The sample had only null or mixed value types for that key, so a specific type could not be inferred.
Do records work with Jackson?
Yes, Jackson 2.12 and later deserialise records directly.
Is my JSON uploaded?
No. The code is generated in your browser.