publicissapient-france/selma

Custom looping mapper

NicoHvt opened this issue · 3 comments

Hie Slemesle,

I didn't found out how to make such kind of things:

@Mapper(ignoreMissingProperties = true,
withIgnoreNullValue = true,
withIoC = IoC.SPRING,
withCyclicMapping = true
)
public interface ShopFullMapper {
@maps(withCustom = {
ShopLightMapper.class
})
ShopDto asShopDto(Shop in);
}

My problem is that a shop contains a link to another shop or another collection of shops and I would like to use a different mapper for the nested objects instead of the origin one. Is it possible inside an object mapper to use a different mapper for the same kind of object ?

If I specify withCustom the FullMapper is ignored and the ShopLightMapper is used instead for all objects. And using withCustomFields is not able to compile, did I forget something or a completely different configuration for that kind of loop mapping ?

Thank you for your help.

Hi,
can you share the compilation error on the withCustomFields sample ?
Another solution would be to use an interceptor that will call the specific mapper on the nested shops after the mapping has been processed while ignoring the shops.

Sorry, I don't have the compilation anymore, I had to find a hot fix. Problem sims to come from collection of objects I can't map with a different mapper for the nested objects than the main one I'm working on.

Hi,

thanks for your reply, the withCustom will use the specified custom mapper for all shop to shop mapping inside asShopDto(...) and its sons.

So using withCustomFields is definitely the good solution, but there can be a bug on it. What was the hotfix you found ? There can be an issue with the withCustomFields while working on collections this probably was the source of the error.
In fact, customFields does not handle object inside collections but does handle collection by themselves.
I'll see if I can find a proper way for collection handling in such case.