Home > Net >  mapper does not convert between dto to entity
mapper does not convert between dto to entity

Time:05-14

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);

CodePudding user response:

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

  • Related