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 InheritMaps to avoid @Maps duplication #138

Closed
slemesle opened this Issue Jan 8, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@slemesle

slemesle commented Jan 8, 2017

Some times we need to reproduce the exact same configuration @Maps multiple times in the mapper.

To avoid code duplication we should introduce the @InheritMaps which will apply the configuration from an inherited @Maps with same type to type mapping. Only the couple means something since configuration are bidirectional.

Sample codes :

@Mapper
public interface ExtendMapper {

    @Maps(withCustomFields = {
            @Field({"Proposal.passenger.age", "ProposalDto.passengerAge"}),
            @Field({"passenger.card", "passengerCard"}),
            @Field({"Proposal.passenger.date", "ProposalDto.passengerDate"})
    }) ProposalDto asProposalDto(Proposal proposal);

    @InheritMaps
    Proposal asProposal(ProposalDto proposal);

    @InheritMaps
    Proposal asProposal(ProposalDto proposal, Proposal out);
}
@Mapper
public interface ExtendNamedMapper {

    @Maps(withCustomFields = {
            @Field({"Proposal.passenger.age", "ProposalDto.passengerAge"}),
            @Field({"passenger.card", "passengerCard"}),
            @Field({"Proposal.passenger.date", "ProposalDto.passengerDate"})
    }) ProposalDto asProposalDto(Proposal proposal);

    @Maps(withIgnoreFields = {"passengerAge", "passengerDate", "passenger", "passengerCard"})
    ProposalDto asReducedProposalDto(Proposal proposal);

    @InheritMaps(method = "asReducedProposalDto")
    Proposal asProposal(ProposalDto proposal);

    @InheritMaps(method = "asReducedProposalDto")
    Proposal asProposal(ProposalDto proposal, Proposal out);
}

@slemesle slemesle added this to the 1.0 Final milestone Jan 8, 2017

@slemesle slemesle added the new feature label Jan 8, 2017

@slemesle slemesle self-assigned this Jan 8, 2017

@slemesle slemesle closed this Feb 22, 2017

slemesle added a commit that referenced this issue Apr 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment