Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTO mapping #97

Closed
Clashsoft opened this issue May 30, 2021 · 0 comments · Fixed by #99
Closed

DTO mapping #97

Clashsoft opened this issue May 30, 2021 · 0 comments · Fixed by #99
Assignees
Labels
feature New feature or request
Milestone

Comments

@Clashsoft
Copy link
Member

Clashsoft commented May 30, 2021

Add a new annotation called @DTO for reflective class building that automatically maps classes to DTOs.

The annotation should have three parameters:

  • Class model (required) - the GenModel class that is used as a base
  • String[] omit (optional, default {}) - the properties that should be omitted. Ignored if empty or pick is present.
  • String[] pick (optional, default {}) - the properties that should be included. Ignored if empty.

Generated DTO classes automatically use the POJO property style. Associations are mapped to String or List/Set<String> fields that may hold the ID of the target objects. In the future, we could add an @ID annotation that could override this behaviour to use another ID type like int, long, UUID, etc..

Example

org/example/model/GenModel:

class GenModel {
  class User {
    String id;
    @Link("user") Address address;
  }

  class Address {
    String id;
    String city;
    String street;
    ...
    @Link("address") User user;
  }

  ...
}

org/example/dto/GenDtos:

class GenDtos {
  @DTO(model = GenModel.User.class, omit = "id")
  class UserDto {
  }

  @DTO(model = GenModel.Address.class, pick = {"id", "street"})
  class AddressDto {
  }

  ...
}
@Clashsoft Clashsoft added the feature New feature or request label May 30, 2021
@Clashsoft Clashsoft self-assigned this May 30, 2021
@Clashsoft Clashsoft added this to the v1.6.0 milestone Jun 12, 2021
@Clashsoft Clashsoft mentioned this issue Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant