johny sinh
johny sinh

Reputation: 43

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

Upvotes: 1

Views: 1479

Answers (1)

mpdgr
mpdgr

Reputation: 355

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

Upvotes: 2

Related Questions