~/tools/-json-to-java-
Type generator - JSON to Java

$ Convert JSON to Java classes

Paste JSON and generate Java POJO classes with typed fields, getters and setters — or Java interfaces.

// controls

JSON Input

Paste a JSON payload and generate typed definitions.

vultio · -json-to-java-

Generated Output

Classes ready to copy.

public class Profile {
    private String displayName;
    private String signupAt;

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    public String getSignupAt() {
        return signupAt;
    }

    public void setSignupAt(String signupAt) {
        this.signupAt = signupAt;
    }
}

public class RootPayload {
    private Integer id;
    private String email;
    private Boolean isActive;
    private List<String> roles;
    private Profile profile;

    public Integer getId() {
        return id;
    }

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

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Boolean getIsActive() {
        return isActive;
    }

    public void setIsActive(Boolean isActive) {
        this.isActive = isActive;
    }

    public List<String> getRoles() {
        return roles;
    }

    public void setRoles(List<String> roles) {
        this.roles = roles;
    }

    public Profile getProfile() {
        return profile;
    }

    public void setProfile(Profile profile) {
        this.profile = profile;
    }
}
§ 01
context

Why use an online JSON to Java class converter

Mapping a JSON response to Java means writing a class with a private field, a getter and a setter for every key — and repeating it for each nested object. It is pure boilerplate, and a single typo breaks deserialization.

This JSON to Java class converter generates those POJOs from a sample payload. Field names match the JSON keys and every field has a getter and setter, which is exactly the convention Jackson (ObjectMapper) and Gson use by default.

Switch the target to Java Interface if you only need getter signatures. Everything runs in your browser, so you can paste real API responses safely.

§ 02
scenarios

JSON to Java class converter use cases

01 →Create DTOs for a Spring Boot REST client (RestTemplate, WebClient, Feign) from an example response.
02 →Model request bodies for a @RestController from the JSON the frontend sends.
03 →Generate classes for Android apps parsing JSON with Gson or Moshi.
04 →Turn a JSON test fixture into a typed object for JUnit tests.
05 →Speed up integration with third-party APIs that have no Java SDK.
§ 03
examples

JSON to Java class converter examples: input and output

POJO with getters and setters

$ input
{"id":1,"name":"Demo"}
↳ output
public class RootPayload { private Integer id; private String name; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }

Arrays become List<T>, nested objects become classes

$ input
{"roles":["admin"],"address":{"city":"Rome"}}
↳ output
public class Address { private String city; ... } public class RootPayload { private List<String> roles; private Address address; ... }
§ 04
troubleshooting

Common JSON to Java class converter errors and how to fix them

! UnrecognizedPropertyException: Unrecognized field

cause:Jackson found a JSON key that has no matching field, usually because the sample did not include every field the API returns.

fix:Add the missing field, or annotate the class with @JsonIgnoreProperties(ignoreUnknown = true).

! cannot find symbol: class List

cause:The generated code uses java.util.List for arrays but imports are not added.

fix:Add import java.util.List; at the top of the file.

! class X is public, should be declared in a file named X.java

cause:Several public classes were pasted into one file.

fix:Move each class to its own file, or make nested classes public static inner classes.

§ 05
workflow

How developers use the JSON to Java class converter in practice

→ Use Lombok to drop the boilerplate

Keep only the private fields and annotate the class with @Data (or @Getter @Setter) — Lombok generates the same accessors at compile time.

→ Prefer records for immutable DTOs on Java 16+

For read-only responses, convert the generated fields into a record: public record User(Integer id, String name) {}. Jackson 2.12+ deserializes records natively.

→ Map snake_case keys with @JsonProperty

If the API uses snake_case, rename the Java field to camelCase and annotate it with @JsonProperty("created_at"), or configure PropertyNamingStrategies.SNAKE_CASE on the ObjectMapper.

§ 06
tradeoffs

When not to use the JSON to Java class converter

01 →When an OpenAPI or JSON Schema contract exists: use openapi-generator or jsonschema2pojo in your build for complete, versioned models.
02 →For polymorphic payloads that need @JsonTypeInfo / @JsonSubTypes — those need hand-written models.
§ 07
limits

JSON to Java class converter limits and implementation notes

~ Inference from a single sample

Optional fields missing from the sample will be missing from the class.

~ Wrapper types only

Integer, Double and Boolean are used so null is representable; switch to primitives where a value is always present.

§ 08
read more

Related guides

§ 09
references

Standards & references

§ 10
toolbox

Related developer tools

§ FAQ
questions

Frequently asked questions about the JSON to Java class converter

What is a POJO generated from JSON?

A POJO (Plain Old Java Object) is a simple class with private fields and public getters and setters. Generating it from a JSON sample gives you a model that Jackson or Gson can map the JSON into without writing every field by hand.


Does the generated class work with Jackson and Gson?

Yes. Field names match the JSON keys and every field has a getter and setter, which is the convention Jackson and Gson use by default. Add annotations such as @JsonProperty only when you want Java names that differ from the JSON keys.


How are JSON types mapped to Java types?

Strings become String, whole numbers Integer, decimals Double, booleans Boolean, arrays List<T> and nested objects their own class. Wrapper types are used instead of primitives so that missing or null values can be represented.


Can I generate interfaces instead of classes?

Yes. Switch the target to Java Interface to get one interface per object with getter signatures only, which is useful for read-only views or proxies.


Do I need to add imports?

If the JSON contains arrays, add import java.util.List; to the file. Put each public class in its own file (or make nested ones static inner classes) to satisfy the Java compiler.


Is my JSON sent to a server?

No. Class generation runs entirely in your browser; the JSON is never uploaded.


Can I use generated Java classes with Lombok or as Java records?

Yes. The generated POJOs with getters and setters can be refactored into Java 14+ records for immutable models, or annotated with Lombok @Data or @Getter/@Setter to reduce boilerplate code.