json to java record & jackson pojo converter

typetools

instant, client-side type converter • 0ms network latency

root:
inputjson
paste or drop file
307 chars
outputjava record
*.java
package com.example.models;

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

public record Metadata(
    @JsonProperty("lastLogin") String lastLogin,
    @JsonProperty("ipAddress") String ipAddress,
    @JsonProperty("failedAttempts") Object failedAttempts
) {}

public record RootPayload(
    @JsonProperty("userId") String userId,
    @JsonProperty("username") String username,
    @JsonProperty("email") String email,
    @JsonProperty("isActive") Boolean isActive,
    @JsonProperty("score") Double score,
    @JsonProperty("roles") List<String> roles,
    @JsonProperty("metadata") Metadata metadata,
    @JsonProperty("tags") List<Object> tags
) {}
0.15ms•in-browser
documentation, edge cases & specifications below

step-by-step integration guide

technical specification differences & end-to-end conversion workflow

Eliminating POJO Boilerplate with Java 17/21 Records and Jackson

Historically, deserializing JSON in Java required verbose Plain Old Java Objects (POJOs) cluttered with mutable fields, getters, setters, equals(), hashCode(), and Lombok bytecode processors. Introduced as a standard feature in Java 16+ and widely adopted in Java 17 and Java 21 LTS, record classes provide compact, shallowly immutable data carriers that Jackson 2.12+ deserializes directly via their canonical constructor without needing a default no-arg constructor or setter methods. However, Java's type system distinguishes between unboxed stack primitives (int, long, double, boolean)—which cannot hold null—and boxed heap reference types (Integer, Long, Double, Boolean).

Canonical Constructor Synthesis, Boxed Nullables, and @JsonProperty Binding

Our JSON-to-Java Record compiler inspects your JSON payload and generates clean public record declarations. Each JSON key is mapped to an idiomatic camelCase record component annotated with Jackson's @JsonProperty("original_key") so ObjectMapper binds snake_case or kebab-case keys without requiring global naming strategy changes. Crucially, the AST analyzer tracks field nullability across array elements: if a numeric or boolean property is always present and non-null, it uses unboxed primitives (long, double, boolean) for zero boxing overhead; if the field can be null or omitted, it promotes the component to its boxed wrapper (Long, Double, Boolean) to prevent Jackson from throwing a MismatchedInputException when encountering JSON null.

frequently asked questions

common developer questions answered

q:When does the generator emit boxed types (Integer, Boolean) vs. primitives (int, boolean) in Java Records?

In Java, primitive types like int and boolean cannot be assigned null. If a JSON field is nullable or absent in some array elements, our generator emits boxed wrapper types (Integer, Long, Double, Boolean) so Jackson can deserialize null values safely.

q:Does Jackson require a no-argument constructor to deserialize Java Records?

No. Jackson 2.12 and newer automatically introspect the canonical constructor of a Java record and bind JSON properties directly to the record components using @JsonProperty annotations.

q:How are JSON arrays typed in the generated Java record?

JSON arrays are typed as java.util.List<T> (e.g., List<String> or List<OrderItem>), which Jackson deserializes as an ArrayList or immutable list out of the box.

topic cluster

related type & ast converters

3 interconnected tools