Skip to content
Advertisement

mapper does not convert between dto to entity

I am new to mapsturct I just want to map between dto to entity those two;

my bank class;

 @Id
 private int id;

my bank dto class;

private Integer bankId;

my mapper below;

BankMapper BANK_MAPPER_INSTANCE = Mappers.getMapper(BankMapper.class);

    @Mapping(target = "bankId", source = "id")
    List<BankDto> convertToBankDto(List<Bank> bank);

Advertisement

Answer

Target and source properties don’t work well with collections mapping. You need additional mapping for single element. Update your mapper as below, so Mapstruct can use element mapper when mapping the collection:

@Mapper
public interface BankMapper {

    BankMapper BANK_MAPPER_INSTANCE = Mappers.getMapper(BankMapper.class);

    List<BankDto> convertToBankDto(List<Bank> bank);

    @Mapping(target = "bankId", source = "id")
    BankDto bankToBankDto(Bank bank);
}

If this doesn’t help, post the rest of your code, so it’s easier to figure out what’s missing

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement