diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Source.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Source.java index fd558bcfb..c1d64d5fc 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Source.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Source.java @@ -26,6 +26,7 @@ public class Source { private Long baz; private int zip; private String someType; + private SomeType forNested; public int getFoo() { return foo; @@ -74,4 +75,12 @@ public class Source { public void setSomeType(String someType) { this.someType = someType; } + + public SomeType getForNested() { + return forNested; + } + + public void setForNested(SomeType forNested) { + this.forNested = forNested; + } } diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetAbstractMapper.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetAbstractMapper.java index c230b7c62..5a146eeb4 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetAbstractMapper.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetAbstractMapper.java @@ -30,10 +30,12 @@ public abstract class SourceTargetAbstractMapper { @Mappings({ @Mapping(source = "qax", target = "baz"), - @Mapping(source = "baz", target = "qax") + @Mapping(source = "baz", target = "qax"), + @Mapping(source = "forNested.value", target = "fromNested") }) public abstract Target sourceToTarget(Source source); + @Mapping(target = "forNested", ignore = true) public abstract Source targetToSource(Target target); protected void isNeverCalled(Source source) { diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java index 98fcc7408..541ccb7c9 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java @@ -31,10 +31,12 @@ public interface SourceTargetMapper { @Mappings({ @Mapping(source = "qax", target = "baz"), - @Mapping(source = "baz", target = "qax") + @Mapping(source = "baz", target = "qax"), + @Mapping(source = "forNested.value", target = "fromNested") }) Target sourceToTarget(Source source); @InheritInverseConfiguration + @Mapping(target = "forNested", ignore = true) Source targetToSource(Target target); } diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Target.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Target.java index 6cec8469d..81cbc4db5 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Target.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Target.java @@ -28,6 +28,7 @@ public class Target { private int qax; private String zip; private SomeType someType; + private String fromNested; public Long getFoo() { return foo; @@ -76,4 +77,12 @@ public class Target { public void setSomeType(SomeType someType) { this.someType = someType; } + + public String getFormNested() { + return fromNested; + } + + public void setFromNested(String fromNested) { + this.fromNested = fromNested; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/NestedPropertyMappingMethod.java index 1e71aa1e2..dcb469bc5 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/NestedPropertyMappingMethod.java @@ -153,6 +153,10 @@ public class NestedPropertyMappingMethod extends MappingMethod { public String getName() { return safeName; } + + public String getAccessorName() { + return getAccessor().getSimpleName().toString(); + } } } diff --git a/processor/src/main/resources/org.mapstruct.ap.model.NestedPropertyMappingMethod.ftl b/processor/src/main/resources/org.mapstruct.ap.model.NestedPropertyMappingMethod.ftl index a04dee806..bd54de636 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.NestedPropertyMappingMethod.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.NestedPropertyMappingMethod.ftl @@ -24,7 +24,7 @@ return ${returnType.null}; } <#list propertyEntries as entry> - <@includeModel object=entry.type/> ${entry.name} = <#if entry_index == 0>${sourceParameter.name}.${entry.accessor}<#else>${propertyEntries[entry_index-1].name}.${entry.accessor}; + <@includeModel object=entry.type/> ${entry.name} = <#if entry_index == 0>${sourceParameter.name}.${entry.accessorName}()<#else>${propertyEntries[entry_index-1].name}.${entry.accessorName}(); <#if !entry.type.primitive> if ( ${entry.name} == null ) { return ${returnType.null};