mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#325 bookkeeping issue in reverse mapping
This commit is contained in:
parent
fa4226a8c2
commit
e4b0d53561
@ -312,12 +312,6 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
|
||||
EnumMappingMethod.Builder builder = new EnumMappingMethod.Builder();
|
||||
mergeWithReverseMappings( reverseMappingMethod, method );
|
||||
if ( method.getMappings().isEmpty() ) {
|
||||
if ( reverseMappingMethod != null && !reverseMappingMethod.getMappings().isEmpty() ) {
|
||||
method.setMappings( reverse( reverseMappingMethod.getMappings() ) );
|
||||
}
|
||||
}
|
||||
|
||||
MappingMethod enumMappingMethod = builder
|
||||
.mappingContext( mappingContext )
|
||||
.souceMethod( method )
|
||||
@ -388,8 +382,19 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
private void mergeWithReverseMappings(SourceMethod reverseMappingMethod, SourceMethod method) {
|
||||
Map<String, List<Mapping>> newMappings = new HashMap<String, List<Mapping>>();
|
||||
if ( reverseMappingMethod != null && !reverseMappingMethod.getMappings().isEmpty() ) {
|
||||
// define all the base mappings based on its forward counterpart
|
||||
newMappings.putAll( reverse( reverseMappingMethod.getMappings() ) );
|
||||
// define all the base mappings based on its forward counterpart.
|
||||
// however, remove the mappings that are designated as constant, expression or ignore.
|
||||
// They are characterized by the key ""
|
||||
|
||||
Map<String, List<Mapping>> reverseMappings = new HashMap<String, List<Mapping>>();
|
||||
reverseMappings.putAll( reverseMappingMethod.getMappings() );
|
||||
List<Mapping> nonSourceMappings = method.getMappings().get( "" );
|
||||
if (nonSourceMappings != null ) {
|
||||
for (Mapping nonSourceMapping : nonSourceMappings) {
|
||||
reverseMappings.remove( nonSourceMapping.getTargetName() );
|
||||
}
|
||||
}
|
||||
newMappings.putAll( reverse( reverseMappings ) );
|
||||
}
|
||||
|
||||
if ( method.getMappings().isEmpty() ) {
|
||||
|
@ -49,7 +49,7 @@ public interface SourceTargetMapper {
|
||||
@InheritInverseConfiguration(name = "forward")
|
||||
@Mappings({
|
||||
@Mapping(target = "someConstantDownstream", constant = "test"),
|
||||
@Mapping(source = "propertyToIgnoreDownstream", ignore = true)
|
||||
@Mapping(target = "propertyToIgnoreDownstream", ignore = true)
|
||||
})
|
||||
Source reverse(Target target);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public interface SourceTargetMapperAmbiguous1 {
|
||||
@InheritInverseConfiguration
|
||||
@Mappings({
|
||||
@Mapping(target = "someConstantDownstream", constant = "test"),
|
||||
@Mapping(source = "propertyToIgnoreDownstream", ignore = true)
|
||||
@Mapping(target = "propertyToIgnoreDownstream", ignore = true)
|
||||
})
|
||||
Source reverse(Target target);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public interface SourceTargetMapperAmbiguous2 {
|
||||
@InheritInverseConfiguration(name = "blah")
|
||||
@Mappings({
|
||||
@Mapping(target = "someConstantDownstream", constant = "test"),
|
||||
@Mapping(source = "propertyToIgnoreDownstream", ignore = true)
|
||||
@Mapping(target = "propertyToIgnoreDownstream", ignore = true)
|
||||
})
|
||||
Source reverse(Target target);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public interface SourceTargetMapperAmbiguous3 {
|
||||
@InheritInverseConfiguration(name = "forward")
|
||||
@Mappings({
|
||||
@Mapping(target = "someConstantDownstream", constant = "test"),
|
||||
@Mapping(source = "propertyToIgnoreDownstream", ignore = true)
|
||||
@Mapping(target = "propertyToIgnoreDownstream", ignore = true)
|
||||
})
|
||||
Source reverse(Target target);
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public interface SourceTargetMapperErroneouslyAnnotated {
|
||||
@InheritInverseConfiguration(name = "forward")
|
||||
@Mappings({
|
||||
@Mapping(target = "someConstantDownstream", constant = "test"),
|
||||
@Mapping(source = "propertyToIgnoreDownstream", ignore = true)
|
||||
@Mapping(target = "propertyToIgnoreDownstream", ignore = true)
|
||||
})
|
||||
Source reverse(Target target);
|
||||
|
||||
|
@ -42,7 +42,7 @@ public interface SourceTargetMapperNonMatchingName {
|
||||
@InheritInverseConfiguration(name = "blah")
|
||||
@Mappings({
|
||||
@Mapping(target = "someConstantDownstream", constant = "test"),
|
||||
@Mapping(source = "propertyToIgnoreDownstream", ignore = true)
|
||||
@Mapping(target = "propertyToIgnoreDownstream", ignore = true)
|
||||
})
|
||||
Source reverse(Target target);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user