Youtilities

Popular

All tools

JSON to Java Class

Generate Java records or POJO classes with Jackson annotations from any JSON.

Runs in your browser. Nothing is uploaded.

Input

Waiting for JSON

Java
Java types appear here.

What this does

Paste JSON and get Java types for it: a record per object (Java 16+), or a classic class with private fields, getters, and setters. Works with Jackson out of the box.

Types

Whole numbers are Long, decimals Double, and booleans Boolean, boxed so null is allowed. Arrays are List<T>. Empty arrays and mixed values become Object.

Names

Fields are camelCase. When that differs from the JSON key (first-name → firstName) a @JsonProperty annotation keeps the original. Two objects with the same shape share one type.

record or class?

A record is immutable and needs Java 16 or later; Jackson reads records from version 2.12. Pick class for older Java, for frameworks that expect a no-argument constructor with setters, or when you need to change values after parsing. Both styles carry the same @JsonProperty annotations, which are only added where the Java name differs from the key, for example first_name → firstName. Java keywords used as keys, such as class or default, get a trailing underscore.

Parsing with Jackson

Read an object with new ObjectMapper().readValue(json, Root.class). When the top level is an array, the output says so and you read it with a TypeReference, for example new TypeReference<List<RootItem>>() {}. Jackson fails by default on keys the class does not declare, with UnrecognizedPropertyException; add @JsonIgnoreProperties(ignoreUnknown = true) to the type, or turn off FAIL_ON_UNKNOWN_PROPERTIES on the mapper, if the API may add fields.

Why Long and not int?

Whole numbers become Long so ids above about 2.1 billion still fit, and all types are boxed so a missing or null value is null rather than 0 or false. Java has no separate marker for a missing key, so missing and null both arrive as null; check for it before unboxing. Mixed or empty arrays become List<Object>. For money, consider changing Double to BigDecimal to avoid rounding.

All json tools