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
ModelMapper mapper.skip() doesn't work for pojo objects with circular dependency #336
Comments
I think the problem is with the mappings modelmapper generates. When I print the mappings of each typeMap this is what I get:
TypeMap |
I found no clean way of solving this problem. But we can add
Now, our test works perfectly.
But this approach also has some drawbacks, as we can't add different types of conditions together and use it as Thanks! |
I think it's annoying that implicit mapping(auto property mapping) do what we don't want it do, but we also need implicit mapping for convenience. I think it's ordering problem that there will be less issue if the implicit mapping is invoked AFTER our manual mappings. For your example, the implicit mappings are created when you create type map, so it's no use to skip the wife after that. I will try to create an api that you can perform implicit mapping after manually mapping. |
Are there any other solutions like, For example, in my case, |
That's what my solution want to solve. Currently, modelmapper don't have any approach to do this. |
hi @imtiazShakil , Thanks. |
Please take a look #337 and GH336.java#L100-L119 that I want to write a test to reproduce your issue with old way. |
hi @imtiazShakil , Can you try our new api?
|
Hi @chhsiao90 , Thanks for the update! I'll give it a try and let you know. |
Hello, @chhsiao90, I checked the code and tried understanding. I've some questions that I don't understand. Approach 1Disabling implicitMapping.
The mapping is exactly What I meant.
Approach 2Default mapping
What I get is this:
The mapping is like before, but still the tests work ok! Can you explain why? When should we use what approach? If implicitMapping is disabled, will modelmapper implicitly create typemaps where no user defined mappings exist? Will it throw exceptions? Thanks! |
About approach 2. that's what I'm asking in my previous comment here that I try to reproduce your bug but I can't. My fix should not affect the approach 2. Maybe there is some changes between old and latest modelmapper that fix the problem.
I think this approach was used when you had some custom type maps, and each type map is based on other type map.
The modelmapper will create empty TypeMap, and there will be no exception. It's a good question, that you sometimes need to disable implicit mappings, but you still need implicit mappings. I will think about how to improve the API. |
With this patch #337 , I also can't reproduce the bug.
Can this problem be fixed if we write configuration like this?
|
Yes, it can fix the problem. But it looks ugly :( |
hi @imtiazShakil , I provide a new API: |
Just release v2.1.0, please take a look. |
Thanks. I'll let you know. |
I have two pojo objects: Husband, Wife which reference each other.
Husband.java
Wife.java
I've created simple typeMap rulings for both objects, where the referenced object is skipped.
My test class:
When mapping updatedHusband to husband, setWife() method is not skipped. But, if I remove typeWife mapping from modelMapper the code works fine.
I'm using ModelMapper 1.1.3
Thanks.
The text was updated successfully, but these errors were encountered: