We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi, this library looks great! What about implementing the uses feature in the @Mapper annotation?
uses
@Mapper
https://mapstruct.org/documentation/dev/reference/html/#_advanced_mapping_options
Using this flag, developers can reduce the code duplication to map existing objects, by plugging other mappers into the parent one.
// TARGET class ParentTarget { ParentTarget(this.childTarget); final ChildTarget childTarget; } class ChildTarget { ChildTarget(this.property); final String property; } // SOURCE class ParentSource { ParentSource(this.childSource); final ChildSource childSource; } class ChildSource { ChildSource(this.property); final String property; }
@Mapper() abstract class ChildMapper { @Mapping(source: 'childSource', target: 'childTarget') ChildTarget toChildTarget(ChildSource model); } @Mapper(uses: [ChildMapper]) abstract class ParentMapper { ParentTarget toParentTarget(ParentSource model); }
The generated code should be something like down below.
class ParentMapperImpl extends ParentMapper { final ChildMapper childMapper; ParentMapperImpl({ required this.childMapper, }) : super(); ParentTarget toParentTarget(ParentSource model) { final parentTarget = ParentTarget(childMapper.toChildTarget(model.childSource)); return parentTarget; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hi,
this library looks great! What about implementing the
uses
feature in the@Mapper
annotation?https://mapstruct.org/documentation/dev/reference/html/#_advanced_mapping_options
Using this flag, developers can reduce the code duplication to map existing objects, by plugging other mappers into the parent one.
Example
Entities
Mappers
The generated code should be something like down below.
The text was updated successfully, but these errors were encountered: