@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public abstract class FooMapper {
@Autowired
static AddressMapper addressMapper;
@Mapping(source = "entity.id", target = "id")
@Mapping(target = "address", qualifiedByName = "mappingAddress")
public abstract FooEntity dtoAndEntityToEntity(FooDto dto, FooEntity entity);
@Named("mappingAddress")
static AddressEntity mappingAddress(FooDto dto, FooEntity entity) {
if (Objects.nonNull(dto) && Objects.nonNull(dto.getAddress())) {
return addressMapper.dtoToEntity(dto.getAddress());
}
if (Objects.nonNull(entity)) {
return entity.getAddress();
}
return null;
}
}
I want to map the address even from entity of dto, if dto is null, I should to use entity info, I used that custom method, but I got and error :
Error:(27,41) java: Several possible source properties for target property "address".
The error is clear, the error happen because entity and dto have address attribute, but I don't want to set the source, I want it to be deducted from entity or dto.
Is there any way to avoid this error please?