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. 1

    Paste the JSON

    A single sample is enough; multiple samples improve nullability detection.

  2. 2

    Pick the library

    Jackson (most common in Spring), Gson (Android and some legacy projects), or plain POJO with no annotations.

  3. 3

    Pick extras

    Lombok for auto-generated getters/setters, builder pattern, equals/hashCode. Or leave it plain.

  4. 4

    Pick nested style

    Sibling classes in the same file (Java 17+ public classes must be separate files) or nested static classes.

  5. 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. int cannot be null; Jackson will throw if the JSON has "age": null. Use Integer.
  • Missing date modules. Jackson needs jackson-datatype-jsr310 for Instant/LocalDate. Without it, dates fall back to String or epoch longs.
  • Sharing wrapper types across unrelated classes. If two JSON shapes both have a nested Address, the generator creates two Address classes. 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

Tool available in other languages