'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);
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |