Convert JSON to Java class!

Input JSON to generate Java DTO/POJO/record code, including nested objects! Supports Jackson @JsonProperty and Lombok. Spring Boot JPA entities and MongoDB documents are in the tabs above.
JSON
Result
 

Convert JSON to Java class!

Paste a JSON sample and get Java classes or records that Jackson can deserialize straight away. Nested objects become additional classes in the same file, and arrays become List<T>.

Use it for the DTOs you would otherwise type by hand in Spring Boot: response types for RestTemplate, WebClient or Feign clients, or request bodies for third-party APIs. On Java 16+ you can emit records, and if your codebase already uses Lombok, the Lombok option keeps the output in the same style.

How to use

  1. Paste the API response JSON into the input box.
  2. Enter the DTO name in Type name. Only the first class is public, so match it to the file name.
  3. Choose class (with getters/setters) or record under Style.
  4. With class, tick Lombok to replace getters/setters with @Data, @NoArgsConstructor and @AllArgsConstructor.
  5. Paste the result into a .java file and add your package declaration.

Example

Input (JSON)
{
  "id": 1296269,
  "full_name": "octocat/Hello-World",
  "private": false,
  "stargazers_count": 80,
  "owner": { "login": "octocat", "site_admin": false },
  "topics": ["api", "demo"]
}
Output (Java · class)
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;

public class Repository {
    private Integer id;
    @JsonProperty("full_name") private String fullName;
    @JsonProperty("private") private Boolean private_;
    @JsonProperty("stargazers_count") private Integer stargazersCount;
    private Owner owner;
    private List<String> topics;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public Boolean getPrivate() {
        return private_;
    }

    public void setPrivate(Boolean private_) {
        this.private_ = private_;
    }

    public Integer getStargazersCount() {
        return stargazersCount;
    }

    public void setStargazersCount(Integer stargazersCount) {
        this.stargazersCount = stargazersCount;
    }

    public Owner getOwner() {
        return owner;
    }

    public void setOwner(Owner owner) {
        this.owner = owner;
    }

    public List<String> getTopics() {
        return topics;
    }

    public void setTopics(List<String> topics) {
        this.topics = topics;
    }
}

class Owner {
    private String login;
    @JsonProperty("site_admin") private Boolean siteAdmin;

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public Boolean getSiteAdmin() {
        return siteAdmin;
    }

    public void setSiteAdmin(Boolean siteAdmin) {
        this.siteAdmin = siteAdmin;
    }
}

snake_case keys such as full_name map to a fullName field via @JsonProperty. private is a Java keyword, so the field became private_ while its accessors stay getPrivate()/setPrivate(), and the owner object was split out into an Owner class in the same file.

Supported features

  • Two output styles: a regular class with getters/setters, or an immutable record.
  • Lombok option (class style only): adds @Data, @NoArgsConstructor, @AllArgsConstructor plus imports and drops the accessor code.
  • @JsonProperty is added only where the field name differs from the JSON key, along with its import.
  • Every field uses a wrapper type (Integer, Long, Double, Boolean), so JSON null fits without extra work.
  • Integers beyond the 32-bit range become Long; values of mixed types become Object.
  • Keyword keys like class or default get a trailing _; keys starting with a digit get an n prefix.
  • Java has no type aliases, so a top-level array produces a // Root: List<RootItem> comment plus the element class.

Use cases

DTOs for third-party APIs in Spring Boot

Paste the sample response from a payment, maps or messaging API's docs and pass the generated class to restTemplate.getForObject(url, PaymentResponse.class). The deeper the nesting, the more fields you avoid missing compared with writing it by hand.

Read-only response models as records

For responses you only read, a record is shorter and has no setters; Jackson 2.12+ deserializes through the record's canonical constructor.

Recovering a model from test fixtures

In a legacy project where only fixture JSON files exist, feed a fixture in to see the field layout and get a first draft of the DTO.

Notes and limitations

  • A field missing from some items simply arrives as null in the wrapper type; nothing marks it as optional. Add @NotNull or similar yourself if you validate required values.
  • With default settings Jackson throws on unknown keys. If the API may add fields, consider @JsonIgnoreProperties(ignoreUnknown = true) or disabling FAIL_ON_UNKNOWN_PROPERTIES.
  • Date strings come out as String. Mapping them to LocalDateTime or OffsetDateTime needs the jackson-datatype-jsr310 module.
  • Choosing record hides the Lombok checkbox, since records don't need it.
  • Nested classes are package-private classes in the same file, not public. Split them into separate files if other packages need them.

FAQ

Why is the getter for a boolean field getXxx and not isXxx?

The field type is the Boolean wrapper, not primitive boolean. Jackson has long recognized isXxx accessors only for primitive boolean, so getXxx is used to make the property bind the same way on any Jackson version.

Does the record output keep @JsonProperty?

Yes, renamed components are written as @JsonProperty("full_name") String fullName. Jackson 2.12 or later fills them through the canonical constructor.

If I set spring.jackson.property-naming-strategy=SNAKE_CASE, can I delete the annotations?

With a global SNAKE_CASE strategy, full_name ↔ fullName maps without annotations. Names changed because of keywords, like private_, are not covered by the strategy, so keep those annotations.

Can I use the output with Gson?

Gson ignores @JsonProperty. Replace it with @SerializedName in the class output and the same structure works with Gson; records are supported from Gson 2.10.