JSON to Java

Convert JSON to Java POJOs, Lombok data models, or Java 16+ records. Supports Jackson @JsonProperty, Gson @SerializedName, and null safety.

100% private · runs locally

Generate Java POJOs, Lombok data classes, or Java 16+ Records from any JSON structure. The tool maps JSON types to correct Java types, generates proper camelCase field names, and optionally adds Jackson or Gson annotations — ready to paste directly into your Maven or Gradle project.

JSON input
Java output Java

Architecture Choices: Standard POJO, Lombok @Data, or Java 16+ Record?

When modeling API data structures in Java, development teams typically choose between three distinct implementation styles depending on their Java version, persistence requirements, and boilerplate tolerance.

1. Standard POJO

Plain Old Java Object with private fields, public getters, setters, and an implicit zero-arg constructor. Universally compatible with all Java versions, reflection libraries, and older frameworks (Spring 3/4, Android API < 26).

2. Project Lombok

Uses compile-time annotation processing via @Data to generate getters, setters, equals(), and toString() in bytecode. Popular in enterprise Spring Boot projects to keep source files concise.

3. Java 16+ Records

Language-level immutable data carriers (public record User(...) {}). Fields are final, accessors omit the get prefix, and state cannot be mutated post-instantiation. Note: cannot be used as JPA/Hibernate entities.

Output Format Comparison (Generated from JSON)
// 1. POJO Style (Full getters & setters)
public class Account {
    @JsonProperty("account_id")
    private int accountId;
    public int getAccountId() { return accountId; }
    public void setAccountId(int accountId) { this.accountId = accountId; }
}

// 2. Lombok Style (Clean annotation-driven class)
@Data
public class Account {
    @JsonProperty("account_id")
    private int accountId;
}

// 3. Record Style (Immutable component carrier, Java 16+)
public record Account(
    @JsonProperty("account_id") int accountId
) {}

Annotation Ecosystems: Jackson (@JsonProperty) vs. Gson (@SerializedName)

JSON payloads standardly employ snake_case (created_at) or kebab-case (item-sku), whereas Java conventions require camelCase (createdAt, itemSku). Annotations bind these mismatched identifiers.

Jackson (com.fasterxml.jackson)

The core JSON engine in Spring Boot and Quarkus. Strict by default: throws UnrecognizedPropertyException if the incoming payload contains unknown keys unless configured otherwise.

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.DeserializationFeature;

ObjectMapper mapper = new ObjectMapper()
    .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

UserResponse response = mapper.readValue(jsonString, UserResponse.class);

Gson (com.google.code.gson)

Google's lightweight JSON parser, widely used in Android applications and Retrofit client adapters. Tolerant by default: silently ignores extra JSON properties without requiring explicit configuration.

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

Gson gson = new GsonBuilder()
    .serializeNulls()
    .create();

UserResponse response = gson.fromJson(jsonString, UserResponse.class);

The Primitive vs. Wrapper Trap (int vs. Integer)

One of the most frequent sources of runtime bugs when ingesting JSON in Java is the distinction between primitive types (int, double, boolean) and their object wrappers (Integer, Double, Boolean).

How Primitive Defaulting Masks Corrupt or Missing Data: If a JSON API field "discount": null or is omitted from the payload, Jackson deserializing into a primitive private int discount; will assign the default value 0. Your business logic cannot distinguish between a real discount of 0% and a missing/unspecified discount. Furthermore, if Gson encounters an explicit null on an unboxed primitive during reflection, it can throw an internal NullPointerException.

Best practice for REST APIs: The generator outputs primitive types (int, double) for clean sample representations, but for production API clients where fields may be optional or nullable, convert fields to boxed wrappers (Integer, Double). Notice that the generator already automatically uses boxed wrappers for generic collections (such as List<Integer>) because Java generics disallow primitive type arguments.

Handling Dates and Timestamps in Java JSON Pipelines

JSON has no native date type; timestamps are formatted as ISO-8601 strings (e.g. "2026-08-15T14:30:00Z") or UNIX epoch integers. The generator emits these fields as String.

When updating generated models to use modern Java Date-Time types (Instant, OffsetDateTime, or LocalDate), Jackson requires the JSR-310 module to be registered:

// Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
mapper.disable(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

Without registering JavaTimeModule, Jackson throws InvalidDefinitionException: Java 8 date/time type `java.time.Instant` not supported by default.

Comparison: jsonutils vs. jsonschema2pojo & IntelliJ IDEA Plugins

A transparent look at how this online tool compares against established tools in the Java ecosystem:

Feature / Tool jsonutils.app (In-Browser) jsonschema2pojo (CLI / Maven) IntelliJ IDEA Plugins (e.g. RoboPOJO)
Setup Required Zero install, opens in any browser Maven/Gradle plugin configuration IDE plugin installation inside IntelliJ
Target Frameworks POJO, Lombok, Java 16+ Records Jackson 1/2, Gson, Moshi, Custom Gson, Jackson, FastJson, AutoValue
JSON Schema Input Raw JSON object/array samples Full JSON Schema Draft-03/04/07 support Raw JSON samples
Privacy & Security 100% Client-side (No data leaves device) Local build / CLI Local inside IDE
Best Workflow Ad-hoc conversions, quick prototyping, multi-OS CI/CD build-time schema-to-class automation Rapid class scaffolding while coding in IntelliJ

If you require automated build-time generation from formalized JSON Schema specifications, jsonschema2pojo is the industry benchmark. For daily ad-hoc tasks, generating Lombok classes, or creating Java 16+ record DTOs without switching tools or configuring build plugins, jsonutils delivers immediate, formatted output.

Related tools

Frequently asked questions

What is a Java POJO?

POJO (Plain Old Java Object) is a simple Java class with private fields and public getters/setters. It has no dependency on any framework. POJOs are the standard pattern for representing JSON data structures in Java — used with Jackson, Gson, Spring Boot, and Android development.

What is Lombok @Data and do I need it?

Lombok is a Java library that generates boilerplate at compile time via annotations. @Data generates getters, setters, equals(), hashCode(), and toString(). It's widely used in Spring Boot projects. Add org.projectlombok:lombok to your build file to use it.

What is a Java Record and when should I use it?

Java Records (Java 16+) are immutable data classes. The compiler auto-generates a constructor, getters (without get prefix), equals(), hashCode(), and toString(). Use records for immutable value objects like API response DTOs. Jackson supports records natively in Jackson 2.12+.

When should I use Jackson vs Gson?

Jackson is the default in Spring Boot and is generally faster and more feature-rich. Gson is Google's library — simpler API, popular in Android development. Both can deserialize JSON into Java classes. Choose based on your existing dependencies: Spring Boot includes Jackson automatically.

How are Java types mapped from JSON values?

JSON strings → String. JSON integers → int. JSON decimals → double. JSON booleans → boolean. JSON null → Object. JSON arrays of objects → List<ClassName>. Nested objects become separate class definitions.

How do I deserialize JSON into the generated Java class?

With Jackson: Root obj = new ObjectMapper().readValue(jsonString, Root.class);. With Gson: Root obj = new Gson().fromJson(jsonString, Root.class);. Make sure the class is on the classpath and all nested classes are in the same file or properly imported.

How do I fix com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException?

Jackson throws this exception when a JSON payload contains properties that have no corresponding Java field. You can resolve this by adding @JsonIgnoreProperties(ignoreUnknown = true) above your Java class, or by configuring your mapper with objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);.

How do I deserialize a JSON array into a List<T> with Jackson and Gson?

Because of Java generic type erasure, you cannot pass List<Item>.class directly. With Jackson, use TypeReference: List<Item> list = mapper.readValue(json, new TypeReference<List<Item>>() {});. With Gson, use TypeToken: List<Item> list = gson.fromJson(json, new TypeToken<List<Item>>() {}.getType());.

Why does Jackson fail to deserialize Java 16+ records with "Cannot construct instance" errors?

Java records do not have parameterless zero-argument constructors or mutable setters. Jackson added native record deserialization support starting in Jackson 2.12. Ensure your project uses jackson-databind version 2.12.0 or higher.