mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#400 fix nested property mappings with Eclipse JDT compiler, extend the integration test accordingly.
This commit is contained in:
parent
2435f0206a
commit
640d9dd571
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -153,6 +153,10 @@ public class NestedPropertyMappingMethod extends MappingMethod {
|
||||
public String getName() {
|
||||
return safeName;
|
||||
}
|
||||
|
||||
public String getAccessorName() {
|
||||
return getAccessor().getSimpleName().toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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}</#if>;
|
||||
<@includeModel object=entry.type/> ${entry.name} = <#if entry_index == 0>${sourceParameter.name}.${entry.accessorName}()<#else>${propertyEntries[entry_index-1].name}.${entry.accessorName}()</#if>;
|
||||
<#if !entry.type.primitive>
|
||||
if ( ${entry.name} == null ) {
|
||||
return ${returnType.null};
|
||||
|
Loading…
x
Reference in New Issue
Block a user