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
Control automapping from root level by allowing @Mapping #1057
Comments
I commented that at another point already, but for the sake of the discussion here: I would expect that the following two declarations would create the same results (just with a different visibility of @Mapping(target = "fish.kind", source = "fish.type")
FishTankDto toFishTankDto(FishTank source); is should basically just be a short-cut to this: FishTankDto toFishTankDto(FishTank source);
@Mapping(target = "kind", source = "type")
FishDto fishToFishDto(Fish fish); And to get the blood pressure up, I'd even say that supporting this behaviour is more important than supporting the selected nested-source to nested-target mapping 😱. |
I think that with #1046 we actually have this implemented. The
Basically we are always going to create automappings for elements that have no mapping. I don't see how this can be a problem. What we currently have open is using Configurations for the automapping it is one of the open points in #1001 |
… a root Mapping method
…ot ignored / lost during grouping
… a root Mapping method
Use ReportingPolicy for explicitly ignoring unmapped target properties in forged methods.
…om root level with @mapping
…n our methods that MapStruct has to create and methods that we create for the internal framework
…om root level with @mapping
…n our methods that MapStruct has to create and methods that we create for the internal framework
Use ReportingPolicy for explicitly ignoring unmapped target properties in forged methods.
…om root level with @mapping
…n our methods that MapStruct has to create and methods that we create for the internal framework
Use ReportingPolicy for explicitly ignoring unmapped target properties in forged methods.
…hods that MapStruct has to create and methods that we create for the internal framework
#1072 has been merged |
Besides the prototype methods in a shared config, it should be possible to control the auto-mapping from the root object graph method. With control I mean:
Currently we have nested source / nested target mappings
@Mapping
to allow arbitrary selection if properties in a source object graph and map those to arbitrary properties in the target object graph. This is done by@Mapping( target = "tbean.propX.propX1", source = "sbean.propY.propY1.propY11" )
. For all clarity: it does not seem to make sense add an ignore option like for instance:@Mapping( target = "tbean.propX.propX2", ignore = true )
, since this property would not have been mapped anyway.Auto-mapping changes things. MapStruct starts to generate mappings automatically based on names. It is essentially different from the nested source / nested target concept however. It requires the source object graph to mirror its target object graph (they are more or less supposed to be symmetrical). MapStruct generates a mapping between each of the properties.
So suppose source:
Now suddenly it would make sense to define mappings.
@Mapping( target = "tbean.propX.propX2", ignore = true)
@Mapping( target = "tbean.propB.probB1", source="sbean.propY.propY1")
The text was updated successfully, but these errors were encountered: