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!