JSON to Java Class
Paste JSON and get Java model classes for Jackson, Spring Boot or any other JSON library. Choose plain POJOs with getters and setters, compact records for Java 16 and later, or Lombok @Data classes. Fields use camelCase with @JsonProperty where the JSON key differs, numbers become int, long or double by value, optional values use boxed types, and ISO dates can become OffsetDateTime.
- Runs in your browser
- No sign-up
- Free to use
How to use JSON to Java Class
- Paste a JSON sample.
- Choose POJO, record or Lombok style.
- Set the root class name and package.
- Copy the code and split classes into files as needed.
JSON to Java Class features
Three styles
Getters and setters, records or Lombok @Data with constructors.
Jackson ready
@JsonProperty for keys that are not valid camelCase names.
Sensible types
int, long, double, boolean, String, List<T> and Object.
Null handling
Boxed Integer, Long, Double and Boolean for optional or null values.
Dates
Optional OffsetDateTime for ISO 8601 strings.
Local
Generated in your browser.
When to use JSON to Java Class
- Creating DTOs for a Spring Boot REST client or controller.
- Modelling a JSON payload for an Android app.
- Mapping a message format for Kafka or RabbitMQ consumers.
- Starting a data model from an API example.
JSON to Java Class FAQ
Why are some fields Integer instead of int?
Primitive int cannot be null. When the sample shows a field missing or null, the boxed type is used so the value can be absent.
Do I need @JsonProperty on every field?
No. It is added only where the Java field name differs from the JSON key, such as "is-active" becoming isActive.
Which style should I pick?
Records are concise and immutable, ideal for DTOs on Java 16+. POJOs work everywhere and with frameworks that need setters. Lombok removes boilerplate if your project already uses it.
Why put each class in its own file?
Java allows only one public top-level class per file, named after the file. Alternatively, make nested classes public static inner classes.
Does OffsetDateTime work out of the box?
With Jackson, register the JavaTimeModule from jackson-datatype-jsr310; Spring Boot does this automatically.
Is my data uploaded?
No. Everything runs in your browser.
Java models for JSON
Java libraries such as Jackson and Gson map JSON onto classes whose fields match the keys. For every object in a payload you need a class, for every array a List, and for every value a Java type that can hold it, including the possibility that it is missing. The generator produces all of that from a sample in one step, following Java naming conventions.
Field names are converted to camelCase. When the result differs from the JSON key, for example for snake_case or hyphenated keys, a @JsonProperty annotation keeps the exact key, so serialization works in both directions without global naming strategies. Reserved words such as class get an underscore so the code compiles.
Types follow the values in the sample. Whole numbers become int or, when they exceed 32 bits, long; decimals become double; true and false become boolean. When a field is missing or null in some objects, the boxed wrapper type is used instead, because a primitive would silently turn a missing value into zero or false.
The three output styles cover the common approaches. Classic POJOs with private fields, getters and setters work with every framework. Records, available since Java 16, give immutable data carriers in a few lines and are supported by Jackson since version 2.12. Lombok’s @Data generates accessors, equals, hashCode and toString at compile time for projects that use it.
All classes are generated together for convenience. Because Java expects one public class per file, move each into its own file or nest them as static inner classes. Then review the types against the real data contract: a sample cannot show which fields are always present or which numbers can grow beyond the values you pasted.