Generate a Lombok @Data POJO from JSON
Skip the getter/setter boilerplate by emitting a Java POJO annotated with Lombok's @Data. Lombok generates accessors, equals, hashCode, and toString at compile time.
Detailed Explanation
Slimming Down with Lombok @Data
Lombok is a Java library that adds annotations like @Data, @Getter, and @Builder to remove repetitive boilerplate. With @Data enabled in this tool, the generated POJO collapses to just the fields — Lombok synthesizes everything else at compile time.
Example JSON
{
"id": 7,
"title": "Inbox Zero",
"completed": false
}
Generated Java with Lombok
package com.example.model;
import lombok.Data;
@Data
public class Todo {
private Integer id;
private String title;
private Boolean completed;
}
What @Data Provides
A single @Data annotation expands at compile time into:
- A getter for every non-static field
- A setter for every non-static, non-final field
- A canonical
equals(Object)implementation - A canonical
hashCode()implementation - A canonical
toString()implementation - A required-args constructor (over final fields)
If you need finer control, use @Getter, @Setter, @EqualsAndHashCode, or @ToString individually.
Maven Dependency
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
Gradle
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
IDE Setup
IntelliJ IDEA and Eclipse both require the Lombok plugin to display the generated methods in autocomplete. The plugin reads the annotations and surfaces the synthetic members, so your IDE can navigate to them as if they existed in source.
Trade-offs
Lombok keeps your model classes readable but introduces a build-time dependency. For library code published to Maven Central or anywhere downstream consumers need to reason about the generated members, prefer explicit getters and setters or switch to records.
Use Case
Spring Boot services, internal microservices, and Android backends with a few dozen DTOs benefit enormously from @Data. Removing accessor noise lets reviewers focus on the actual fields and validation logic.