JSON to Java Class Converter

Generate Java classes with getters and setters from JSON, plus a Jackson-based Converter.

Generate Java POJOs from JSON

Mapping JSON in Java usually means writing a POJO for every object, with private fields, getters, setters and annotations. This converter generates them from a sample: each object becomes a class with Jackson @JsonProperty annotations on its accessors, nested objects become separate classes, arrays become typed arrays, and whole numbers become long. A Converter class with fromJsonString and toJsonString methods wraps the Jackson ObjectMapper setup, including date and time parsing helpers.

How to use

  1. Paste a JSON sample, for example a REST response your Spring or Android app consumes.
  2. Enter the root class name, for example Customer.
  3. Add jackson-databind to your Maven or Gradle build, move each class into its own .java file in your package, and call Converter.fromJsonString(json).

Frequently asked questions

Why is the output so long?
Java needs explicit fields, getters and setters, and the generated Converter includes date-time helpers for the java.time API. If you only need the models, copy the data classes and use your existing ObjectMapper.
Can I use Java records or Lombok instead?
The generator writes classic classes for maximum compatibility. You can convert them to records (Java 16+) or annotate them with Lombok's @Data after copying; Jackson supports both.
Does it work with Spring Boot?
Yes. Spring Boot uses Jackson by default, so the annotated classes can be used directly as @RequestBody or response types without the Converter class.

Example: JSON to Java

Input JSON

{
  "customerId": 501,
  "fullName": "Grace Hopper",
  "vip": true,
  "addresses": [{ "city": "Arlington", "zip": "22201" }]
}

Generated Java (Customer)

// Converter.java

// To use this code, add the following Maven dependency to your project:
//
//
//     com.fasterxml.jackson.core     : jackson-databind          : 2.9.0
//     com.fasterxml.jackson.datatype : jackson-datatype-jsr310   : 2.9.0
//
// Import this package:
//
//     import io.quicktype.Converter;
//
// Then you can deserialize a JSON string with
//
//     Customer data = Converter.fromJsonString(jsonString);

package io.quicktype;

import java.io.IOException;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.*;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;

public class Converter {
    // Date-time helpers

    private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder()
            .appendOptional(DateTimeFormatter.ISO_DATE_TIME)
            .appendOptional(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
            .appendOptional(DateTimeFormatter.ISO_INSTANT)
            .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SX"))
            .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssX"))
            .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
            .toFormatter()
            .withZone(ZoneOffset.UTC);

    public static OffsetDateTime parseDateTimeString(String str) {
        return ZonedDateTime.from(Converter.DATE_TIME_FORMATTER.parse(str)).toOffsetDateTime();
    }

    private static final DateTimeFormatter TIME_FORMATTER = new DateTimeFormatterBuilder()
            .appendOptional(DateTimeFormatter.ISO_TIME)
            .appendOptional(DateTimeFormatter.ISO_OFFSET_TIME)
            .parseDefaulting(ChronoField.YEAR, 2020)
            .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)
            .parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
            .toFormatter()
            .withZone(ZoneOffset.UTC);

    public static OffsetTime parseTimeString(String str) {
        return ZonedDateTime.from(Converter.TIME_FORMATTER.parse(str)).toOffsetDateTime().toOffsetTime();
    }
    // Serialize/deserialize helpers

    public static Customer fromJsonString(String json) throws IOException {
        return getObjectReader().readValue(json);
    }

    public static String toJsonString(Customer obj) throws JsonProcessingException {
        return getObjectWriter().writeValueAsString(obj);
    }

    private static ObjectReader reader;
    private static ObjectWriter writer;

    private static void instantiateMapper() {
        ObjectMapper mapper = new ObjectMapper();
        mapper.findAndRegisterModules();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        SimpleModule module = new SimpleModule();
        module.addDeserializer(OffsetDateTime.class, new JsonDeserializer<OffsetDateTime>() {
            @Override
            public OffsetDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
                String value = jsonParser.getText();
                return Converter.parseDateTimeString(value);
            }
        });
        mapper.registerModule(module);
        reader = mapper.readerFor(Customer.class);
        writer = mapper.writerFor(Customer.class);
    }

    private static ObjectReader getObjectReader() {
        if (reader == null) instantiateMapper();
        return reader;
    }

    private static ObjectWriter getObjectWriter() {
        if (writer == null) instantiateMapper();
        return writer;
    }
}

// Customer.java

package io.quicktype;

import com.fasterxml.jackson.annotation.*;

public class Customer {
    private long customerID;
    private String fullName;
    private boolean vip;
    private Address[] addresses;

    @JsonProperty("customerId")
    public long getCustomerID() { return customerID; }
    @JsonProperty("customerId")
    public void setCustomerID(long value) { this.customerID = value; }

    @JsonProperty("fullName")
    public String getFullName() { return fullName; }
    @JsonProperty("fullName")
    public void setFullName(String value) { this.fullName = value; }

    @JsonProperty("vip")
    public boolean getVip() { return vip; }
    @JsonProperty("vip")
    public void setVip(boolean value) { this.vip = value; }

    @JsonProperty("addresses")
    public Address[] getAddresses() { return addresses; }
    @JsonProperty("addresses")
    public void setAddresses(Address[] value) { this.addresses = value; }
}

// Address.java

package io.quicktype;

import com.fasterxml.jackson.annotation.*;

public class Address {
    private String city;
    private String zip;

    @JsonProperty("city")
    public String getCity() { return city; }
    @JsonProperty("city")
    public void setCity(String value) { this.city = value; }

    @JsonProperty("zip")
    public String getZip() { return zip; }
    @JsonProperty("zip")
    public void setZip(String value) { this.zip = value; }
}

Convert JSON to other languages