Convert JSON to Java POJOs
What JSON-to-POJO conversion actually changes, where type inference goes wrong, and when a Map or tree model beats generated Java classes.
Converting JSON to Java POJOs (plain old Java objects) means turning a sample JSON document, or a JSON Schema, into Java class source code whose fields mirror the JSON structure. Searches like "json 2 pojo" usually come from developers who want typed classes for an API response without writing them by hand. This review covers whether that transformation suits your use, what it changes, and where the generated code stops matching the data it came from.
Is JSON-to-POJO conversion right for your use?
Generated POJOs are a good fit when the JSON shape is stable and you will read the same structure many times in Java code. The main benefit is compile-time typing: field names autocomplete, typos fail at compile time rather than at runtime, and the structure is documented in code. The key tradeoff is that a generator only knows what it was shown. A single example document is a sample, not a contract, so the inferred types are guesses that you must review.
Keep the data untyped, as a Map or a tree model such as Jackson's JsonNode, when:
- The payload shape varies by request, tenant or version and you only read a few fields.
- You are writing a one-off script or a quick inspection tool.
- Keys are dynamic, for example IDs used as object keys, so they cannot become fixed field names.
- You need to pass the JSON through unchanged, and a typed model could drop unknown fields or reformat values.
If the API publishes a JSON Schema or an OpenAPI description, generating from that is usually more reliable than generating from an example. A schema states types, required fields and allowed values that a single sample cannot show.
What the conversion actually changes
Nothing happens to the JSON itself. The converter reads its structure and writes new artifacts: Java source files. Each JSON object becomes a class, each key becomes a field, nested objects become separate classes, and arrays become List fields. Depending on the tool and settings, the output may also include getters and setters, constructors, equals and hashCode, and annotations for a particular JSON library.
There are two layers to keep apart. The generated classes are the stored change: code that now lives in your project. The mapping between JSON and those classes happens at runtime through a library such as Jackson or Gson, which follows the annotations and naming rules in that code. If the classes and the real JSON drift apart, the library is where you will see errors or silently missing data.
The phrase "json 2 pojo" is ambiguous. It may refer to the general technique, to the open-source project jsonschema2pojo (which accepts JSON Schema or example JSON and also offers build-tool plugins), or to various online converters and IDE plugins. These differ in options and output style, and this review did not test any specific tool.
An illustrative example
The following input and output were written by hand to show the typical mapping. They are not output captured from any particular converter.
{
"order_id": 1001,
"customer_name": "A. Example",
"items": [
{ "sku": "X-1", "quantity": 2, "price": 9.5 }
],
"created_at": "2026-01-15T10:00:00Z",
"notes": null
}
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
public class Order {
@JsonProperty("order_id")
private Integer orderId;
@JsonProperty("customer_name")
private String customerName;
private List<Item> items;
@JsonProperty("created_at")
private String createdAt;
private Object notes;
// getters and setters omitted
}
public class Item {
private String sku;
private Integer quantity;
private Double price;
// getters and setters omitted
}
Several decisions in this output are worth questioning, and they are typical of what generators produce from a single sample:
- orderId became Integer because 1001 fits, but real IDs may exceed the int range; Long is often safer.
- price became Double because the sample held 9.5. Floating-point types are a poor fit for money; BigDecimal avoids rounding errors.
- createdAt stayed a String because JSON has no date type. Mapping it to Instant or OffsetDateTime requires a deliberate change and the right library module.
- notes became Object because the sample value was null, so there was no type to infer.
- Snake_case keys were renamed to camelCase fields, and @JsonProperty preserves the original key names for serialization.
Will the generated code stay usable after you copy or share it?
The output is ordinary source text. It copies, diffs and reviews like any other Java code, and it uses no special display characters, so it is read like any other source file in an editor or by a screen reader. Whether it remains usable depends less on the text itself and more on how well it matches the data and your project.
Fidelity limits to check
- Type inference: a whole number in the sample produces an integer type, so a later value like 3.5 will fail to deserialize or be truncated, depending on settings.
- Empty arrays and nulls: the generator cannot infer element or field types, so expect Object or List<Object> placeholders.
- Optional fields: a field missing from your sample will be missing from the class. Unless the mapper is set to ignore unknown properties, later payloads that include it may cause errors.
- Invalid identifiers: keys containing hyphens or spaces, keys that start with a digit, or keys that are Java reserved words such as class must be renamed and annotated.
- Polymorphism: when an array mixes object shapes, a single inferred class cannot represent it without type-discriminator handling written by hand.
- Library lock-in: annotations target one library. Jackson uses @JsonProperty and Gson uses @SerializedName, so code generated for one does not carry its mappings to the other.
Fit with your project
Check that the output matches your conventions before committing it: package names, whether you use Lombok, and whether you prefer Java records for immutable data. Recent Jackson releases can deserialize records, which makes them a concise alternative to getter-and-setter classes. Also decide early whether the classes will be regenerated or hand-maintained. Hand edits to generated files are lost on the next regeneration, so teams that regenerate usually do it from a schema in the build rather than by pasting output.
Sharing sample data with a converter
An online converter receives whatever JSON you paste into it. A tool's appearance or wording says nothing reliable about whether it stores or logs input. Unless its documented practices meet your requirements, use a synthetic sample with realistic structure but fake values, or generate locally with an IDE plugin or a build-tool plugin.
Evidence gaps
No specific converter was tested for this review, so there are no verified claims about any tool's output quality, option set, performance or data handling. The type-inference behavior described above follows from how sample-based generation works, but exact defaults, such as Integer versus Long or Double versus BigDecimal, vary by tool and configuration. Check those defaults against the documentation of the tool you choose.
Bottom line
Generating POJOs from JSON saves typing and gives you compile-time safety, but the result is a draft inferred from limited evidence. Use it for stable, frequently used structures. Prefer a schema over a sample, and review numeric, date, null and naming decisions before relying on the classes. For variable or pass-through payloads, a Map or a JSON tree model is the more honest representation.