1001Ferramentas
Converters

JSON to Java Class

Convert JSON to a Java POJO class with getters/setters and inferred types. Supports nested classes and arrays as List. Everything in your browser.

Generate the POJO from an endpoint response

The endpoint returned an object with twenty fields and you need the matching class to deserialise with Jackson or Gson. Typing out a field, a getter and a setter for each one is the kind of work where mistakes do not show up at compile time. They show up in production, as a null field nobody can explain. Paste the JSON and get the class back with types inferred and nested objects split into their own classes.

Type inference looks at values, not names. Text becomes String, true or false becomes boolean, a whole number becomes long, a number with a decimal point becomes double, and null becomes Object. An array becomes a List parameterised by the first element's type, using the boxed Long and Double because Java generics reject primitives. A nested object gets its own class named after the key in PascalCase, and an array of objects gets an Item suffix.

The sharp edge: field names come out exactly as they appear in the JSON. A key called first_name becomes a field with an underscore and a getFirst_name method, and a key with a hyphen or a space produces an identifier that will not compile at all. Rename before pasting or after generating. Every class is marked public, so split them into files or drop the modifier on the inner ones. No Jackson annotations, no Lombok, no equals or toString. Runs in the browser.

Frequently asked questions

Why long instead of int?
Because JSON does not tell you whether the value fits in an int, and silently overflowing is worse than spending eight bytes. Narrow it to int on the fields whose range you know.
Does it add Jackson annotations?
No. You get a plain class with private fields, getters and setters. If the JSON uses snake_case, add @JsonProperty or set a naming strategy on your mapper.
Can the JSON root be an array?
No, the root has to be an object. Paste one representative element instead, or wrap everything in an object with a key, then use List in your own signature.

Related Tools