Prefer realistic decimals
A field that only ever shows whole numbers becomes long. Include a fractional example if your API can return currency-style decimals; otherwise widen the field to double by hand.
Paste a sample payload on the left; Java POJO source appears on the right.
An order with customer, line items, a null coupon and a shipped timestamp
This page posts your JSON sample to /api/convert so the server can emit Java classes. We do not persist the body in a database, and application logs do not record it. An in-memory cache may keep the result for at most one hour. Strip secrets before converting.
Feed the converter a representative payload. Review the POJOs before wiring ObjectMapper or Gson in your service.
Paste an object or array that mirrors production responses, or upload a .json file. If the editor reports a syntax problem, fix it with the JSON validator first.
{
"orderId": 9001,
"customer": {
"fullName": "Mei Chen",
"email": "[email protected]",
"loyaltyTier": "gold"
},
"lineItems": [
{ "sku": "KB-01", "quantity": 2, "unitPrice": 49.9, "giftWrap": true },
{ "sku": "MS-07", "quantity": 1, "unitPrice": 18, "giftWrap": false }
],
"shippedAt": "2026-10-20T14:30:00Z",
"couponCode": null,
"notes": ["leave at door", "fragile"]
}Root is the entry class. Nested objects such as customer and lineItems become their own public classes with getters and setters.
// Root.java
package io.quicktype;
import java.time.OffsetDateTime;
public class Root {
private long orderID;
private Customer customer;
private LineItem[] lineItems;
private OffsetDateTime shippedAt;
private Object couponCode;
private String[] notes;
public long getOrderID() { return orderID; }
public void setOrderID(long value) { this.orderID = value; }
public Customer getCustomer() { return customer; }
public void setCustomer(Customer value) { this.customer = value; }
public LineItem[] getLineItems() { return lineItems; }
public void setLineItems(LineItem[] value) { this.lineItems = value; }
public OffsetDateTime getShippedAt() { return shippedAt; }
public void setShippedAt(OffsetDateTime value) { this.shippedAt = value; }
public Object getCouponCode() { return couponCode; }
public void setCouponCode(Object value) { this.couponCode = value; }
public String[] getNotes() { return notes; }
public void setNotes(String[] value) { this.notes = value; }
}
// Customer.java
package io.quicktype;
public class Customer {
private String fullName;
private String email;
private String loyaltyTier;
public String getFullName() { return fullName; }
public void setFullName(String value) { this.fullName = value; }
public String getEmail() { return email; }
public void setEmail(String value) { this.email = value; }
public String getLoyaltyTier() { return loyaltyTier; }
public void setLoyaltyTier(String value) { this.loyaltyTier = value; }
}
// LineItem.java
package io.quicktype;
public class LineItem {
private String sku;
private long quantity;
private double unitPrice;
private boolean giftWrap;
public String getSku() { return sku; }
public void setSku(String value) { this.sku = value; }
public long getQuantity() { return quantity; }
public void setQuantity(long value) { this.quantity = value; }
public double getUnitPrice() { return unitPrice; }
public void setUnitPrice(double value) { this.unitPrice = value; }
public boolean getGiftWrap() { return giftWrap; }
public void setGiftWrap(boolean value) { this.giftWrap = value; }
}Copy or download the source, change the package name, then deserialize with Jackson or Gson in your service layer.
What this JSON to Java converter picks when it reads your sample values.
| In the JSON sample | In the Java output |
|---|---|
| JSON string | Java String |
| Integer without fraction | long |
| Decimal number | double |
| Boolean literal | boolean (or Boolean if sometimes absent) |
| Nested object | Separate public class |
| Homogeneous object array | Typed array, e.g. LineItem[] |
| String list | String[] |
| ISO-8601 instant | OffsetDateTime |
| Property missing on some rows | Wrapper type (Boolean, String, …) |
A field that only ever shows whole numbers becomes long. Include a fractional example if your API can return currency-style decimals; otherwise widen the field to double by hand.
Generated OffsetDateTime fields deserialize cleanly once Jackson registers JavaTimeModule. Without it, mapping those properties fails at runtime.
Property names, getters, and what happens when array elements disagree.
Keys such as fullName stay camelCase. Hyphenated or spaced keys become legal Java identifiers (for example api-key → apiKey).
When only some array elements include a property, the generator emits Boolean or String so absence can be null instead of a primitive default.
Source blocks declare package io.quicktype;. Replace it with your module package before review.
Hyphens, reserved words, leading digits and spaces are normalized into getters.
// {"api-key":"k","class":"demo","3dModel":1,"XMLHttp":true,"order id":9}
package io.quicktype;
public class Root {
private String apiKey;
private String rootClass;
private long the3DModel;
private boolean xmlHTTP;
private long orderID;
public String getAPIKey() { return apiKey; }
public void setAPIKey(String value) { this.apiKey = value; }
public String getRootClass() { return rootClass; }
public void setRootClass(String value) { this.rootClass = value; }
public long getThe3DModel() { return the3DModel; }
public void setThe3DModel(long value) { this.the3DModel = value; }
public boolean getXMLHTTP() { return xmlHTTP; }
public void setXMLHTTP(boolean value) { this.xmlHTTP = value; }
public long getOrderID() { return orderID; }
public void setOrderID(long value) { this.orderID = value; }
}Always-present sku stays String. Optional giftWrap / label become wrappers.
// [{"sku":"KB-01","qty":2,"giftWrap":true},{"sku":"MS-07","qty":1},{"sku":"CB-02","qty":3,"label":"rush"}]
package io.quicktype;
public class Root {
private String sku;
private long qty;
private Boolean giftWrap;
private String label;
public String getSku() { return sku; }
public void setSku(String value) { this.sku = value; }
public long getQty() { return qty; }
public void setQty(long value) { this.qty = value; }
public Boolean getGiftWrap() { return giftWrap; }
public void setGiftWrap(Boolean value) { this.giftWrap = value; }
public String getLabel() { return label; }
public void setLabel(String value) { this.label = value; }
}Minimal ObjectMapper setup for the generated Root class.
Pretty-print round-trips after registering the Java time module.
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());
Root order = mapper.readValue(payload, Root.class);
System.out.println(order.getCustomer().getFullName());
System.out.println(order.getShippedAt());
Root fromFile = mapper.readValue(new File("order.json"), Root.class);
String encoded = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(fromFile);Edit the generated source when these cases show up in production payloads.
Stick with getters and setters, or manually introduce Lombok / records after generation.
Snake_case APIs may need annotations or a PropertyNamingStrategies setting on ObjectMapper.
Arrays that mix scalars and objects deserve JsonNode or a custom deserializer rather than a single POJO element type.
Reverse direction and sibling language generators.
Use Java to JSON for Map/HashMap-style snippets.
Generate Go structs, C# models, or TypeScript types from the same payload family.
Run it through the JSON validator before retrying.
JSON to Java questions about POJO fields, OffsetDateTime, wrappers and Jackson
Edit, format, and beautify JSON
Validate, fix, and inspect JSON
Compare, measure, and map JSON
Convert JSON to other formats
Convert other formats to JSON
Convert, format, fix, and minify XML
Generate code and format other languages