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
WIP: #2092 merge unmappedSourceProperties of BeanMappings #2096
WIP: #2092 merge unmappedSourceProperties of BeanMappings #2096
Conversation
Thanks for taking over this one @chris922. Let me try to answer the points one by one. I also haven't looked at the code yet. Talking conceptually right now.
I would say we shouldn't join. We have never joined anything up to now. Usually what you define in your current config overrides what is defined in the next config. For example you can override a
What would the backwards compatibility be here. Up to now we only took over if there was not
Yes it can be completely different mapper config. Perhaps this is even wrong now, because if there is not |
as I wrote in #2092 we have a fairly complex hibernate domain model containing multi-level inheritance, some beans implement several interfaces and there are quite a few On the other hand I don't want to miss changes in the domain model (I'm not the only one working on it), therefore I use a strict MapperConfig regarding source and target properties:
Because of this, I have to use And because of the afore mentioned complexity of the domain model I have to ignore the same source properties (which are often just Since my DTOs are structured similar to the domain model (in terms of inheritance) this could be avoided if In my opinion this would feel natural. ;-) Or how about an additional parameter to tackle this use case ( |
@drahkrub just out of curiosity are your |
@filiphr Good point. In my case the getters are indeed annotated (with @Transient), but in Hibernate one can choose between annotating the getters (properties) or the fields, see e.g. this epic discussion on SO. In the latter case one does not have to use the transient annotation on "utility getters". So in my case the workaround you've proposed would probably work, on the other hand it would be anything but flexible, because maybe it could sometimes be desirable to include transient getters into some mapping... |
We've had a discussion about this functionality with the team and we stand by my previous comment
The entire pattern in MapStruct is that if you override a value in an annotation like @chris922 thanks anyways for the work and sorry for closing it, but sometimes we have to take decisions like this 😢 |
I tackled #2092 and it was more complicated than I thought. Maybe it is even though not a bug, but now an enhancement.
Starting point are the changes in
MappingMethodOptions
.I noticed that
@BeanMapping
will not be merged at all and in case a method is annotated with@BeanMapping
and@InheritConfiguration
the@BeanMapping
will not be inherited and/or merged.Therefore I implemented inheritance by following the pattern used for
DelegatingOptions
. The main idea is: If a method inherits the configuration and both methods are annotated with@BeanMapping
I set the inherited@BeanMapping
as the nextDelegatingOptions
.This will ensure that all options of the other
@BeanMapping
will be inherited.For the
ignoreUnmappedSourceProperties
stuff I had to implement a logic to join the lists.I added the same logic for
@MapMapping
and@IterableMapping
as well.The following questions came up during the analyze and implementation:
ignoreUnmappedSourceProperties
at all? Imho we should do this because I probably would also expect this. Nevertheless there might be some reasons that the method inheriting the configuration should have an own configuration of these propertiesSelectionParameters
correctly, right now I try to join the qualifiers, but maybe that is not the right way and they shouldn't be joinednext
of theBeanMappingOptions
? Could it be that there will then be a totally different inheritance flow? Looked for me that the delegating options works in the way thatnext
in this case is the@Mapper
config, then the@MapperConfig
and so on. Now I changenext
to the other@BeanMapping
and maybe this will lead to a different@Mapper
config? Could this be?!I marked this PR as WIP to get some first feedback from you, if everything is fine I would like to update the documentation to highlight that the properties will be merged