Skip to content

Nested target properties uses same method for different mappings #1148

@filiphr

Description

@filiphr

It comes from this Stack Overflow question.

In a nutshell:

@Mapper
public interface MyMapper {

@Mappings({
        @Mapping(source = "senderId", target = "sender.id"),
        @Mapping(source = "recipientId", target = "recipient.id")
    })
    Entity toEntity(Dto dto);
}

Generates:

public class MyMapperImpl implements MyMapper {

    @Override
    public Entity toEntity(Dto dto) {
        if ( dto == null ) {
            return null;
        }

        Entity entity = new Entity();

        entity.setRecipient( dtoToClient( dto ) );
        entity.setSender( dtoToClient( dto ) );

        return entity;
    }

    protected Client dtoToClient(Dto dto) {
        if ( dto == null ) {
            return null;
        }

        Client client = new Client();

        client.setId( dto.getRecipientId() );

        return client;
    }
}

It should generate 2 dtoToClient methods instead of one. We most probably need to extend the the PropertyMapping to have the nested name as well and use that somehow in the equals

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions