Convert JSON to Java Record with Jackson (Practical Guide + Online Tool)

Published: (January 4, 2026 at 07:03 AM EST)
3 min read
Source: Dev.to

Source: Dev.to

Cover image for Convert JSON to Java Record with Jackson (Practical Guide + Online Tool)

Sam T

Parsing JSON into Java types is a daily task for backend developers. With Java 17 records now part of the language, immutable data models are easier to write and maintain. But the truth is: most tutorials still show you how to map JSON to POJOs, not to records, and they rarely cover tooling that saves time.

In this post, I’ll walk through converting JSON to Java 17 records using Jackson, explain the annotations that matter, and share how to automate this with an online generator. I’ll also show how the Toolshref JSON‑to‑Java code converter for records fits into real workflows.


Why Use Java Records for JSON Data?

Java records are simple, immutable data carriers introduced in Java 16 and finalized in Java 17.

They provide:

  • Concise syntax – no boilerplate constructors, getters, equals/hashCode, toString.
  • Immutability by default – fields are final.
  • Better alignment with JSON APIs where data objects are just containers.

In APIs built on Spring Boot, Quarkus, or Micronaut, records reduce clutter and keep focus on business logic. But developers often ask:

“Can Jackson deserialize JSON into a Java record?”

Yes – but with a couple of rules you need to know.

Jackson JSON to Record: What Works Out of the Box

Jackson 2.12+ supports Java records natively. That means:

  • Jackson maps JSON properties to record components.
  • No setters are required.
  • The canonical constructor receives the values directly.

Example JSON

{
  "id": 101,
  "name": "Alice",
  "email": "alice@example.com"
}

Equivalent Java record

public record User(int id, String name, String email) {}

Deserialization with Jackson

ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(jsonString, User.class);

If JSON keys match record component names, Jackson wires them automatically.

When You Need Jackson Annotations for Records

There are cases where defaults aren’t enough:

  • JSON uses snake_case but Java uses camelCase.
  • You want to ignore unknown properties.
  • You need custom date/time formats.

Jackson annotations work with records just as they do with POJOs.

@JsonProperty

Use @JsonProperty when JSON keys don’t match record field names:

public record User(
    @JsonProperty("user_id") int id,
    @JsonProperty("full_name") String name
) {}

@JsonIgnoreProperties

If your input JSON has extra fields you don’t care about:

@JsonIgnoreProperties(ignoreUnknown = true)
public record User(int id, String name) {}

@JsonFormat

Useful for dates:

public record Event(
    int id,
    @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
    LocalDateTime timestamp
) {}

Common Jackson Pitfalls With Records

1. Missing No‑Arg Constructor

Records don’t have a no‑arg constructor, which can break older frameworks that expect one. Jackson doesn’t need it if the canonical constructor matches all components. If you need more control, use @JsonCreator:

public record User(int id, String name) {
    @JsonCreator
    public User(@JsonProperty("id") int id,
                @JsonProperty("name") String name) {
        this.id = id;
        this.name = name;
    }
}

2. Nested JSON Objects

Jackson handles nested structures automatically as long as corresponding Java types exist.

JSON

{
  "id": 5,
  "profile": {
    "age": 30,
    "status": "active"
  }
}

Java records

public record Profile(int age, String status) {}

public record User(int id, Profile profile) {}

Jackson resolves the nested fields without extra code.

Use the Toolshref JSON‑to‑Java Record Converter (Hands‑On)

I built and use this tool regularly when mapping API responses to Java models. It’s straightforward and eliminates the manual pain.

👉 Use it here

How It Works

  1. Paste your JSON.
  2. Choose Record as the target type.
  3. Get ready‑to‑use Java 17 record classes.

Example output for the earlier JSON

public record User(int id, String name, String email) {}

For nested JSON, it generates:

  • Separate record files for each nested object.
  • Properly typed nested records.

Instead of hand‑coding nested records, the tool does it instantly.

Why This Matters

In teams where backend APIs evolve quickly, keeping models in sync is a chore. Using an online JSON‑to‑record converter:

  • Reduces human errors.
  • Enforces consistent naming.
  • Produces code you can immediately refine.

This speeds up development, improves maintainability, and lets you focus on business logic rather than boilerplate mapping code.

  • Integrating third‑party APIs or prototyping.
Back to Blog

Related posts

Read more »

Spring Data JPA Relationships

Introduction Happy New Year! In the past ten days of my full‑stack journey, I have been working on projects right after joining. Initially, I struggled with Re...