Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom looping mapper #189

Open
NicoHvt opened this issue Feb 23, 2018 · 3 comments
Open

Custom looping mapper #189

NicoHvt opened this issue Feb 23, 2018 · 3 comments

Comments

@NicoHvt
Copy link

NicoHvt commented Feb 23, 2018

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.

@slemesle
Copy link

slemesle commented Mar 6, 2018

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.

@NicoHvt
Copy link
Author

NicoHvt commented Mar 13, 2018

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.

@slemesle
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants