EasyEntityToDTO
February 12, 2026 ยท View on GitHub
A lightweight annotation processor to automatically generate DTOs and DTO mappers from your Java entities with zero boilerplate.
๐ง Installation
Using JitPack:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.Marcel091004.EasyEntityToDTO</groupId>
<artifactId>entity-to-dto-core</artifactId>
<version>v1.2.0</version>
</dependency>
๐ Quick Start Example
Here's how you can eliminate boilerplate and generate a DTO in seconds:
โ๏ธ Step 1: Annotate your entity
@ToDTO // ๐ Automatically generates a DTO and Mapper
@DTOExtraFields({ // โ Add custom fields to your DTO
@DTOExtraField(name = "isAdmin", type = "boolean", defaultValue = "false"),
@DTOExtraField(name = "displayName", type = "String")
})
public class ExampleUser {
private String username;
@DTOName(name = "age_in_years") // Change the name in the DTO to whatever you like :)
private int age;
@ExcludeFromDTO // ๐ Won't appear in the DTO
private String password;
public ExampleUser(String username, int age, String password) {
this.username = username;
this.age = age;
this.password = password;
}
public ExampleUser() {} // Default constructor is required for mapper instantiation
}
๐ ๏ธ What Gets Generated?
public class ExampleUserDTO {
private String username;
private int age_in_years; // โ field was renamed from Entity
private boolean isAdmin = false; // โ custom field with default
private String displayName; // โ custom field
}
๐ Step 2: Use the generated Mapper
ExampleUser john = new ExampleUser("John Doe", 25, "secret123");
ExampleUserDTO dto = ExampleUserDTOMapper.mapToExampleUserDTO(john);
System.out.println(dto.getUsername()); // โ John Doe
System.out.println(dto.getAge()); // โ 25
System.out.println(dto.isAdmin()); // โ false
System.out.println(dto.getDisplayName()); // โ null
// OR
ExampleUser user1 = new ExampleUser("alice", 30, "secret123");
ExampleUser user2 = new ExampleUser("bob", 25, "hunter2");
List<ExampleUser> usersList = new ArrayList<>();
usersList.add(user1);
usersList.add(user2);
List<ExampleUserDTO> dtosList = ExampleUserDTOMapper.mapToExampleUserDTO(usersList);
๐ฏ Features
- โ Automatic DTO generation
- โ Automatic Mapper generation
- โ
Exclude fields with
@ExcludeFromDTO - โ
Add virtual fields with
@DTOExtraFieldsโ even if they donโt exist in the original class! - โ Set default values for extra fields
- โ Clean output with no boilerplate
- โ Fast compile-time processing using Java Annotation Processing (APT)
๐ Why Use This?
- โจ Less boilerplate
- ๐งผ Clean and simple annotations
- โก Works out of the box
- ๐ Fast and lightweight
- ๐ฎ Supports both real and custom fields via reflection
๐ฆ Output File Location
Generated files will be located in the target/generated-sources/annotations directory (or your IDEโs generated sources folder).
๐ Contributing Have an idea? Found a bug? Want to add features? Feel free to open an issue or a pull request โ contributions welcome!