JSON to Java Class
Paste a JSON sample and the generator emits one or more Java classes with the right field types, getters, setters and JSON library annotations. Supports Jackson (@JsonProperty), Gson (@SerializedName), and Lombok (@Data/@Builder) for cleaner code. Nested objects become inner or sibling classes, depending on the layout you pick.
How to convert JSON to Java
-
1
Paste the JSON
A single sample is enough; multiple samples improve nullability detection.
-
2
Pick the library
Jackson (most common in Spring), Gson (Android and some legacy projects), or plain POJO with no annotations.
-
3
Pick extras
Lombok for auto-generated getters/setters, builder pattern, equals/hashCode. Or leave it plain.
-
4
Pick nested style
Sibling classes in the same file (Java 17+ public classes must be separate files) or nested static classes.
-
5
Copy the code
Drop into your project. Class names match JSON keys; package is set to what you configure.
Example output: Jackson + Lombok
Input:
{ "firstName": "Alice", "age": 30, "address": { "city": "Madrid" } }
Output:
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class User {
@JsonProperty("firstName")
private String firstName;
@JsonProperty("age")
private int age;
@JsonProperty("address")
private Address address;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Address {
@JsonProperty("city")
private String city;
}
Type mapping
| JSON | Java type |
|---|---|
| string | String |
| integer (<= Integer.MAX) | Integer / int |
| large integer | Long / BigInteger |
| decimal | Double / BigDecimal |
| boolean | Boolean / boolean |
| ISO date | LocalDate (Jackson JSR-310) |
| ISO datetime | Instant / OffsetDateTime |
| null (with non-null sibling) | Wrapper type (e.g. Integer) |
| array | List<T> |
| object | Nested class |
Choosing boxed vs primitive
- Primitive (
int,long,boolean), non-nullable, efficient, no auto-boxing. - Boxed (
Integer,Long,Boolean), nullable, required if the field can be absent or null in JSON.
The generator defaults to boxed for anything seen as nullable, primitive otherwise.
Jackson vs Gson
| Feature | Jackson | Gson |
|---|---|---|
| Ubiquity in Spring | Yes, default | No (need config) |
| Performance | Faster | Slower |
| JSR-310 date support | Via extra module | Via extra module |
| Polymorphism | @JsonTypeInfo |
RuntimeTypeAdapter |
| Trailing comma tolerance | No (by default) | Yes |
Common mistakes
- Using primitive types for nullable fields.
intcannot be null; Jackson will throw if the JSON has"age": null. UseInteger. - Missing date modules. Jackson needs
jackson-datatype-jsr310forInstant/LocalDate. Without it, dates fall back toStringor epoch longs. - Sharing wrapper types across unrelated classes. If two JSON shapes both have a nested
Address, the generator creates twoAddressclasses. Rename or unify manually. - Forgetting
@JsonIgnoreProperties(ignoreUnknown = true). Strict Jackson throws on unknown properties; add this annotation (or configure globally) for tolerant deserialization.
Frequently Asked Questions
Jackson in most cases, it is the Spring default, faster, and has richer polymorphism support. Gson is lighter and better known in Android, though Android projects increasingly use Moshi or kotlinx.serialization.
Lombok cuts a lot of boilerplate (getters, setters, equals, hashCode, builder). It’s widely used but requires the Lombok annotation processor in your build. Disable it if your project avoids Lombok for dependency-hygiene reasons.
Fields that are null in any observed sample become boxed types (Integer instead of int), so they can hold null. Jackson then deserializes "age": null without error. Add @JsonInclude(Include.NON_NULL) to skip nulls on serialization.
Yes, if you select “record”. Records are concise, immutable, and work with Jackson 2.12+. For Spring Boot 3 projects, records plus Lombok-free generation is the modern choice.
Related Tools
ASCII Table Reference
Full ASCII table from 0 to 127 with decimal, hex, octal, binary, standard names and HTML numeric-reference notation, including NUL, LF and DEL.
Color Palette Generator
Generate monochromatic, analogous, complementary, triadic or tetradic color palettes from a base HEX color and export copy-ready CSS variables.
HTML Character Reference
Searchable list of HTML entities, their named and numeric codes, and a one-click copy for special characters and symbols.
FPS Counter
Measure browser FPS with requestAnimationFrame, smoothing, min/max frame rate, warnings and an optional graph. Runs locally with no upload or API.
HEX Color Picker
Pick or enter a HEX colour and get RGB, HSL, approximate CMYK, relative luminance and contrast ratios against white and black.
JSON Formatter
Paste JSON to pretty-print with 2 or 4 spaces, minify it to compact output, or run a quick syntax check before copying the result.
Tool available in other languages
- JSON ke Kelas Java [ID]
- JSON a Clase Java [ES]
- JSON vers classe Java [FR]
- JSON para Classe Java [PT]
- JSON을 Java 클래스로 [KO]
- JSON إلى فئة Java [AR]
- JSON zu Java-Klasse [DE]
- JSON naar Java-klasse [NL]
- JSON เป็นคลาส Java [TH]
- JSON sang lớp Java [VI]
- JSON till Java-klass [SV]
- JSON na klasę Java [PL]
- JSON から Java クラスへ [JA]
- JSON in classe Java [IT]
- JSON в класс Java [RU]
- JSON'dan Java Sınıfına [TR]
- JSON 转 Java 类 [ZH]