"category": "code-generator",
JSON to Java Class (POJO) Generator
"tldr": Paste JSON and get Java POJO classes with private fields and getters/setters - ready for Jackson or Gson deserialization.
Convert a JSON payload into Java POJO classes with private fields, getters, and setters - the shape Jackson and Gson expect. Nested objects become their own classes, arrays become List<T>, and JSON keys are converted to camelCase field names.
Generating POJOs from a real response is dramatically faster than writing them by hand, especially for deeply nested API payloads where a single missed field means a silent null at runtime.
How to convert JSON to Java classes
- 1Paste a representative JSON payload into the input panel.
- 2Each nested object becomes its own class; arrays become List<T> with the element type inferred.
- 3JSON keys are camelCased for the Java fields - configure your mapper for snake_case keys (see FAQ).
- 4Copy the classes into your project and deserialize with Jackson or Gson.
Convert JSON to Java class in code
ObjectMapper mapper = new ObjectMapper()
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
Root order = mapper.readValue(json, Root.class);
System.out.println(order.getCustomer().getName());Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
Root order = gson.fromJson(json, Root.class);Frequently asked questions
My JSON keys are snake_case - how does mapping work?
With Jackson, either annotate fields with @JsonProperty("order_id") or set PropertyNamingStrategies.SNAKE_CASE on the ObjectMapper. With Gson, use @SerializedName("order_id") or FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES. One mapper-level setting is usually cleaner than per-field annotations.
Why long and double instead of int and float?
JSON does not bound number sizes, and IDs or timestamps routinely overflow int. long and double are the safe defaults; narrow specific fields when you know their range.
Can I use records instead of POJOs?
Yes - on Java 16+ records work with Jackson out of the box: record Customer(String name, String email) {}. Convert the generated classes to records if you do not need mutability; the field structure transfers directly.
How do nullable fields work?
Reference types (String, List, nested classes) are simply null when the JSON field is null or absent. For primitives, use the boxed types (Long, Double, Boolean) on fields that can be null - a primitive long cannot hold null and Jackson will fail or default it.
Last updated:
You might also need
Free and in-browser, like everything on JSON Console. Browse all tools →