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

Add a shorthand for mapping from one object with similar fields #5

Open
zikani03 opened this issue Jun 4, 2024 · 0 comments
Open

Comments

@zikani03
Copy link
Member

zikani03 commented Jun 4, 2024

When using DTOs it is common to have classes with similar fields, and it can get annoying real quick to have to type the getter calls on the source object even though gensett can generate the setter calls on the target.
Imagine we have

class User {
  String username;
  String address;
}

class UserDto {
  String username;
  String address;
}

And I want to write a hand-written mapper class or method

public static UserDto map(User user) {
 var dto = new UserDto(); 
 // dto:username,address
 // the line above is a gensett line which creates setters
 dto.setUsername(/* TODO: set me */);
 dto.setAddress(/* TODO: set me */);
}

Proposal:

Add a new shorthand and capability to the library to enable mapping from source to object.
target:<source>:field
target:setm:<source>:field

Where source is the other object

public static UserDto map(User user) {
 var dto = new UserDto();
  // the line below is a gensett line which creates setters
 // map:dto:user:username,address
 // setm:dto:user:username,address

 // the result shall be
 dto.setUsername(user.getUsername());
 dto.setAddress(user.getAddress());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant