Paste a JSON sample and get Java classes or records that Jackson can deserialize straight away. Nested objects become additional classes in the same file, and arrays become List<T>.
Use it for the DTOs you would otherwise type by hand in Spring Boot: response types for RestTemplate, WebClient or Feign clients, or request bodies for third-party APIs. On Java 16+ you can emit records, and if your codebase already uses Lombok, the Lombok option keeps the output in the same style.
Type name. Only the first class is public, so match it to the file name.class (with getters/setters) or record under Style.class, tick Lombok to replace getters/setters with @Data, @NoArgsConstructor and @AllArgsConstructor..java file and add your package declaration.{
"id": 1296269,
"full_name": "octocat/Hello-World",
"private": false,
"stargazers_count": 80,
"owner": { "login": "octocat", "site_admin": false },
"topics": ["api", "demo"]
}import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
public class Repository {
private Integer id;
@JsonProperty("full_name") private String fullName;
@JsonProperty("private") private Boolean private_;
@JsonProperty("stargazers_count") private Integer stargazersCount;
private Owner owner;
private List<String> topics;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public Boolean getPrivate() {
return private_;
}
public void setPrivate(Boolean private_) {
this.private_ = private_;
}
public Integer getStargazersCount() {
return stargazersCount;
}
public void setStargazersCount(Integer stargazersCount) {
this.stargazersCount = stargazersCount;
}
public Owner getOwner() {
return owner;
}
public void setOwner(Owner owner) {
this.owner = owner;
}
public List<String> getTopics() {
return topics;
}
public void setTopics(List<String> topics) {
this.topics = topics;
}
}
class Owner {
private String login;
@JsonProperty("site_admin") private Boolean siteAdmin;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public Boolean getSiteAdmin() {
return siteAdmin;
}
public void setSiteAdmin(Boolean siteAdmin) {
this.siteAdmin = siteAdmin;
}
}
snake_case keys such as full_name map to a fullName field via @JsonProperty. private is a Java keyword, so the field became private_ while its accessors stay getPrivate()/setPrivate(), and the owner object was split out into an Owner class in the same file.
class with getters/setters, or an immutable record.@Data, @NoArgsConstructor, @AllArgsConstructor plus imports and drops the accessor code.@JsonProperty is added only where the field name differs from the JSON key, along with its import.Integer, Long, Double, Boolean), so JSON null fits without extra work.Long; values of mixed types become Object.class or default get a trailing _; keys starting with a digit get an n prefix.// Root: List<RootItem> comment plus the element class.Paste the sample response from a payment, maps or messaging API's docs and pass the generated class to restTemplate.getForObject(url, PaymentResponse.class). The deeper the nesting, the more fields you avoid missing compared with writing it by hand.
For responses you only read, a record is shorter and has no setters; Jackson 2.12+ deserializes through the record's canonical constructor.
In a legacy project where only fixture JSON files exist, feed a fixture in to see the field layout and get a first draft of the DTO.
null in the wrapper type; nothing marks it as optional. Add @NotNull or similar yourself if you validate required values.@JsonIgnoreProperties(ignoreUnknown = true) or disabling FAIL_ON_UNKNOWN_PROPERTIES.String. Mapping them to LocalDateTime or OffsetDateTime needs the jackson-datatype-jsr310 module.record hides the Lombok checkbox, since records don't need it.public. Split them into separate files if other packages need them.getXxx and not isXxx?The field type is the Boolean wrapper, not primitive boolean. Jackson has long recognized isXxx accessors only for primitive boolean, so getXxx is used to make the property bind the same way on any Jackson version.
record output keep @JsonProperty?Yes, renamed components are written as @JsonProperty("full_name") String fullName. Jackson 2.12 or later fills them through the canonical constructor.
spring.jackson.property-naming-strategy=SNAKE_CASE, can I delete the annotations?With a global SNAKE_CASE strategy, full_name ↔ fullName maps without annotations. Names changed because of keywords, like private_, are not covered by the strategy, so keep those annotations.
Gson ignores @JsonProperty. Replace it with @SerializedName in the class output and the same structure works with Gson; records are supported from Gson 2.10.