Код: Выделить всё
public class RewardClaim {
private PlayerEntity owner; // PlayerEntity extends Entity which has a .getId()
}
Код: Выделить всё
public class RewardClaimResponseModel {
private String ownerId;
}
Код: Выделить всё
Converter entityToEntityIdConverter = context -> {
Entity entity = context.getSource();
return entity != null ? entity.getId() : null;
};
modelMapper.typeMap(RewardClaim.class, RewardClaimResponseModel.class)
.addMappings(mapper -> mapper.using(entityToEntityIdConverter)
.map(RewardClaim::getOwner, RewardClaimResponseModel::setOwnerId));
Код: Выделить всё
private UserEntity user; -> private String userId; // Another example
Код: Выделить всё
modelMapper.typeMap(Object.class, Object.class)
.addMappings(mapper -> mapper.using(entityToEntityIdConverter)
.map(FIND HERE THE get FUNCTION, FIND HERE THE set FUNCTION));
Одна из моих последних попыток здесь (в основном псевдокод): https://pastebin.com/gy5g5fXa
Это кажется выполнимым, но мне не повезло. Есть идеи, как я могу этого добиться?
Подробнее здесь: https://stackoverflow.com/questions/787 ... ic-mapping
Мобильная версия