Issue when using Selma as custom mapper
hamavaro opened this issue · 2 comments
hamavaro commented
Hi,
I'm trying to map a specific field in an entity with a custom mapper like this.
/**
* DefaultMapper is an interface.
* Created by mohamedharrouch on 10/05/2017.
*/
@Mapper(ignoreMissingProperties = true,
withIgnoreNullValue = true,
withIoC = IoC.SPRING,
withCyclicMapping = true
)
interface WalletLightMapper {
/**
* Convert Wallet to WalletDto.
*
* @param in Wallet to convert.
* @return converted WalletDto.
*/
@Maps(withIgnoreFields = {
"campaignWalletLinks",
"cardConsumedOnWalletLinks",
"privilegeWalletLinks"
})
WalletDto asWalletDtoLight(Wallet in);
}
This custom mapper is used in another mapper to map a specific field like this
Mapper(ignoreMissingProperties = true,
withIgnoreNullValue = true,
withIoC = IoC.SPRING,
withCyclicMapping = true,
withCustom = {MoneyToMoneyCustomMapper.class, JsonToJsonCustomMapper.class}
)
public interface ReasonMapper {
/**
* Convert Reason to ReasonDto.
*
* @param in Reason to convert.
* @return converted ReasonDto.
*/
@Maps(withCustomFields = {
@Field(value = "wallet", withCustom = WalletLightMapper.class),
@Field(value = "company", withCustom = CompanyLightMapper.class)
}, withIgnoreFields = {
"campaignReasonLinks"
})
ReasonDto asReasonDto(Reason in);
I'm getting an exception during the build in this line
if (inReason.getWallet() != null) {
out.setWallet(customMapperWalletLightMapper.asWalletDtoLight(inReason.getWallet(), instanceCache));
}
Required : ... Wallet
Found : fr.xebia.extras.selma.InstanceCache.
Any idea about what's going wrong ?
Thanks
slemesle commented
Hi,
yes the cyclic mapping protection does not work between different generated mapper.
Because, the custom mapper generated field customMapperWalletLightMapper
refers to the interface WalletLightMapper
and not the generated class.
I should have a closer look to this to find a solution.