Skip to content

JSON to Java Class Converter - POJOs and Records

Input JSON
Java Output

Classes for Jackson from a sample payload

Paste a JSON response and get one Java type per object shape: either a class with private fields and getters/setters, or a record. Field names are camelCase, Java keywords get a trailing underscore (class becomes class_), and with Jackson annotations on, every field carries @JsonProperty with the original key, so renaming a field later doesn't break the mapping.

Example: a customer with contacts

Input, with the root type name set to Customer:

{
  "customerId": 88123,
  "name": "Acme Ltd",
  "active": true,
  "creditLimit": 2500.75,
  "contacts": [
    { "email": "[email protected]", "phone": null },
    { "email": "[email protected]", "phone": "+64 4 555 0101", "primary": true }
  ]
}

Output with Style set to record:

import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;

public record Customer(
    @JsonProperty("customerId") long customerId,
    @JsonProperty("name") String name,
    @JsonProperty("active") boolean active,
    @JsonProperty("creditLimit") double creditLimit,
    @JsonProperty("contacts") List<Contact> contacts
) {}

public record Contact(
    @JsonProperty("email") String email,
    @JsonProperty("phone") String phone,
    @JsonProperty("primary") Boolean primary
) {}

primary is missing from the first contact, so it is Boolean and comes through as null rather than false. customerId is long, never int, because JSON IDs regularly pass 2,147,483,647. Each type is a top-level declaration; put them in separate files, or nest them as static members of one class.

The class style

The default style writes JavaBeans. Here is Contact from the same input:

public class Contact {
    @JsonProperty("email")
    private String email;
    @JsonProperty("phone")
    private String phone;
    @JsonProperty("primary")
    private Boolean primary;

    public String getEmail() { return email; }
    public void setEmail(String value) { this.email = value; }

    public String getPhone() { return phone; }
    public void setPhone(String value) { this.phone = value; }

    public Boolean getPrimary() { return primary; }
    public void setPrimary(Boolean value) { this.primary = value; }
}

The getter for a wrapper Boolean is getPrimary(). Only primitive boolean fields get isActive(), which is the JavaBeans rule Jackson follows. No package line or constructors are generated; add your package and paste the classes in.

Before you commit it

Dates stay String. Change them to Instant or LocalDate and register JavaTimeModule from jackson-datatype-jsr310 (Spring Boot does this for you). Empty JSON objects become Map<String, Object>, and fields with mixed or unknown types become Object. A root-level array produces the item type plus a comment such as // Root: List<RootItem>. Read it with mapper.readValue(json, new TypeReference<List<Item>>() {}).

Validating payloads before they reach Jackson? Generate a JSON Schema from the same sample. If your validator stops at draft-07 (everit does), pick that draft in the options.

Same JSON, other languages

Every generator here reads the sample the same way, so a key that is optional or nullable in one language is optional or nullable in the others. Paste the same input into: TypeScript, Zod, Go, Python, Rust, C#, JSON Schema.

Related Tools

Frequently Asked Questions

Records or classes?
Records if you're on Java 16+ and the object is read-only data, which most API responses are. Jackson deserializes records through the canonical constructor from version 2.12. Pick classes if a framework needs a no-arg constructor and setters, for example JPA entities or older libraries.
When do I get `long` and when `Long`?
Primitives (`long`, `double`, `boolean`) are used when the field was present and non-null in every sample. If it was null or missing anywhere, you get the wrapper (`Long`, `Double`, `Boolean`) so the value can be null. A primitive would quietly become 0 or false instead.
Does it support Gson or Lombok?
No. The only annotation option is Jackson's `@JsonProperty`. With Gson, untick Jackson annotations and add `@SerializedName` where the JSON key isn't a valid Java name. For Lombok, delete the generated getters and setters and add `@Data`, or switch to records, which give you accessors, `equals`, `hashCode` and `toString` without a dependency.
Why did 2500.0 come out as long?
The browser's JSON parser reads `2500.0` as the integer 2500, so the generator can't tell it was written with a decimal point. Change the field to `double` by hand, or include a sample with a fraction. For money, `BigDecimal` is the safer type anyway.
My JSON has extra fields and Jackson throws. What now?
A plain `ObjectMapper` fails on unknown properties by default. Put `@JsonIgnoreProperties(ignoreUnknown = true)` on the class or record, or call `mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)`. Spring Boot's auto-configured mapper already turns that check off.