Browser processing Input is processed on your device. Privacy & storage

JSON to Java

Generate a compilable Java class from a JSON sample — POJO, record or Lombok, with Jackson annotations where they are actually needed.

JSON input
Java output

Three styles, one file

Child types are emitted as nested static classes inside the root class rather than as separate top-level types. That is not a stylistic choice — Java allows only one public top-level class per file, and the filename has to match it. Nesting means the download is a single .java file that compiles the moment you drop it into your source tree.

  • Class with getters and setters — the classic POJO. Verbose, but it works with every framework and every Java version from 8 upwards.
  • Record — one line per component, immutable, no boilerplate. Needs Java 16 or newer.
  • Lombok @Data — fields stay terse and the accessors are generated at compile time. Needs the Lombok dependency.

How types map

JSON valueJava typeNotes
whole numberlongBecomes Long when the field was null somewhere.
decimal numberdoubleBecomes Double when nullable.
true / falsebooleanBecomes Boolean when nullable.
stringStringReference type already.
arrayList<T>Element types are always boxed — List<long> is not legal Java.
objectnested static classShared by every field that references it.
nullboxed typeA primitive cannot hold null, so the wrapper is used instead.

Jackson annotations only where they help

A field whose Java name already matches the JSON key gets no annotation at all — the output stays readable. @JsonProperty appears only when the key could not survive as a Java identifier, or when its camelCase form differs from the wire spelling:

public class Root {
    private long id;

    private String name;

    @JsonProperty("first-name")
    private String firstName;

    @JsonProperty("user id")
    private String userId;
}

Because the annotation is conditional, the com.fasterxml.jackson.annotation import is emitted only when at least one field needs it.

Deserialising the payload

ObjectMapper mapper = new ObjectMapper();
Root payload = mapper.readValue(body, Root.class);
System.out.println(payload.getAddress().getCity());

Edge cases worth knowing

  • Primitive versus wrapper is a real difference. If a field was ever null in your sample, it must be the boxed type or Jackson will throw on the first null.
  • Records are immutable. Jackson can deserialise them from Java 16 onward but needs the parameter names to be retained (-parameters) or an explicit @JsonProperty — which the generator adds whenever the names differ.
  • Mixed arrays like [1, "two"] have no common Java type, so the element becomes Object and you cast at the call site.
  • Lombok nesting is required. A static modifier is only legal on a nested class, so the child classes are emitted inside the root class body.

FAQ

Which style should I pick?

On Java 16 or newer, records give you the shortest correct output. If you are on Java 8 or 11, or you need mutable objects for a framework such as JPA, use the POJO style. Lombok is the middle ground when it is already in your build.

Do I need Jackson?

Only if you use the annotations. If none of your keys needed renaming, the output has no Jackson dependency and works with Gson, Moshi or plain reflection as well.

Why is the file named after the root class?

Java requires a public class to live in a file of the same name. The download button names the file for you, so renaming the root updates the filename too.

Is my JSON uploaded?

No — the generation happens entirely in this browser tab.