1. Home
  2. Developer tools
  3. JSON to Java Record

JSON to Java Record

Create immutable Java records for a REST response in seconds, ready for Jackson or Spring Boot’s RestClient.

Free, no sign-up. Runs in your browser: nothing is uploaded.

How to use JSON to Java Record

  1. Paste JSON.
  2. Set the package and root record name.
  3. Copy the records into your source tree.

Features

  • Java 16+ records, one per object shape
  • camelCase components with @JsonProperty where keys differ
  • Long, Double and Boolean so null values fit
  • List<T> for arrays; Object for mixed values
  • @JsonIgnoreProperties(ignoreUnknown = true) on every record

Supported formats

You can open

  • JSON
  • JSON Lines
  • Typed or pasted text

You get

  • JAVA
  • Copied text

Private by design

Your files are opened and processed by your browser on this device. They are never uploaded to openWorkstand or anyone else, so the JSON to Java Record is safe for contracts, IDs, photos and work documents. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • Records need Java 16 or later and Jackson 2.12 or later.

Guide

Java records for Jackson from a JSON sample

Data transfer objects are the plumbing of every Java service that talks to another API. Since Java 16, records make them short: one line declares the fields, the constructor, the accessors, equals, hashCode and toString. This generator turns a JSON sample into records ready for Jackson, the JSON library behind Spring Boot.

Why records

A record such as public record Item(String sku, Long qty) {} replaces dozens of lines of getters and constructor boilerplate, and its immutability suits data received from elsewhere. Jackson has supported records since version 2.12, and Spring Boot 2.5 and later ship a compatible version, so RestClient, WebClient and RestTemplate can deserialise into them directly.

Names and @JsonProperty

Java components are camelCase. When a JSON key already is, it is used as is; otherwise the component is renamed and annotated: @JsonProperty("order_id") Long orderId. Keys that are Java keywords, such as class or default, get a Value suffix plus the annotation. Every record also gets @JsonIgnoreProperties(ignoreUnknown = true), so a field the API adds later does not break deserialisation.

Boxed types on purpose

Numbers are Long and Double, and booleans Boolean, rather than the primitives. A primitive cannot hold null, and a missing key would silently become 0 or false; with boxed types, absent and null values stay null so your code can tell. Arrays become List<T>, and values whose type varies between samples become Object.

Dates

Switch on date types and ISO 8601 timestamps become OffsetDateTime, keeping the time-zone offset from the string. Jackson needs the Java time module for these, which Spring Boot registers for you.

Using the records

With a plain ObjectMapper: User user = mapper.readValue(json, User.class);. In Spring: restClient.get().uri(url).retrieve().body(User.class). For a JSON array at the root, read into List<User> with a TypeReference.

A worked example

The sample user produces User, Order, Item and Address records. The order_id key becomes @JsonProperty("order_id") Long orderId, is_admin becomes isAdmin, and the tags array becomes List<String> tags. Because the sample’s total includes a decimal, total is a Double.

When records do not fit

Records need Java 16 or later. For older codebases, turn each record into a class with private final fields, a constructor annotated @JsonCreator and getters, or add Lombok’s @Value. If you need mutable objects for a framework such as JPA, write ordinary classes instead; records are not entities.

Testing the mapping

Keep one real response as a test resource and write a small test that reads it into the root record and checks a few values. When the provider changes a type or renames a key, that test fails in your build instead of in production. Jackson’s FAIL_ON_UNKNOWN_PROPERTIES stays off thanks to the annotation, so additions never break it.

Arrays and wrapped responses

Many APIs wrap results, as in {"data": [...], "page": 2}. Paste the whole response: the wrapper becomes the root record and the items get their own record, so paging fields are typed too.

Records with Kotlin or Groovy callers

Records are ordinary Java types to other JVM languages: Kotlin sees the components as properties and Groovy as getters, so a shared model module can serve all of them without changes.

Create the same models in Kotlin with JSON to Kotlin or for .NET with JSON to C#, turn a curl example into Java HttpClient code with cURL to Code, or tidy the sample in the JSON Formatter.

Checked against the current version of the JSON to Java Record on .

Troubleshooting

The file does not open

Check that it is one of the supported formats above and opens in another app. Damaged files and password-protected PDFs cannot be read until they are repaired or unlocked.

It is slow or stops on a very large file

Everything runs on your device, so speed depends on its memory. Close other tabs, use a computer rather than a phone, or split the file into smaller parts first.

The download did not start

Look for your browser’s download bar or icon. Some browsers ask once before a site may download files; allow it and click the button again.

Frequently asked questions

Do I need anything for OffsetDateTime fields?

Register the jackson-datatype-jsr310 module (JavaTimeModule) on your ObjectMapper. Spring Boot registers it automatically; in plain Java call mapper.registerModule(new JavaTimeModule()) or findAndRegisterModules().

Are records immutable?

Their components are final and there are no setters, so the record itself cannot change. A List component can still be modified unless you copy it with List.copyOf in a compact constructor.

Can I split the records into separate files?

Yes. Public top-level types must each live in a file named after them, so move each record into its own .java file in the same package, or nest them as static members of one class.

Does Jackson support records?

Yes, since Jackson 2.12. Spring Boot 2.5 and later include a compatible version, so records work with RestTemplate, WebClient and RestClient without extra configuration.

Can I get classes with getters instead?

The generator writes records. For older Java versions, turn each record into a class with private fields, a constructor and getters, or use Lombok’s @Value on a class with the same fields.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.