mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3670 Fix regression when using InheritInverseConfiguration
with nested target properties and reversing target = "."
This commit is contained in:
parent
b452d7f2c8
commit
60cd0a4420
@ -5,6 +5,7 @@
|
||||
### Bugs
|
||||
|
||||
* Inverse Inheritance Strategy not working for ignored mappings only with target (#3652)
|
||||
* Fix regression when using `InheritInverseConfiguration` with nested target properties and reversing `target = "."` (#3670)
|
||||
|
||||
### Documentation
|
||||
|
||||
|
@ -362,7 +362,13 @@ public class NestedTargetPropertyMappingHolder {
|
||||
Map<String, Set<MappingReference>> singleTargetReferences = new LinkedHashMap<>();
|
||||
for ( MappingReference mapping : mappingReferences.getMappingReferences() ) {
|
||||
TargetReference targetReference = mapping.getTargetReference();
|
||||
String property = first( targetReference.getPropertyEntries() );
|
||||
List<String> propertyEntries = targetReference.getPropertyEntries();
|
||||
if ( propertyEntries.isEmpty() ) {
|
||||
// This can happen if the target property is target = ".",
|
||||
// this usually happens when doing a reverse mapping
|
||||
continue;
|
||||
}
|
||||
String property = first( propertyEntries );
|
||||
MappingReference newMapping = mapping.popTargetReference();
|
||||
if ( newMapping != null ) {
|
||||
// group properties on current name.
|
||||
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.ap.test.bugs._3670;
|
||||
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Named;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@Mapper
|
||||
public interface Issue3670Mapper {
|
||||
|
||||
@Mapping(target = "name", source = ".", qualifiedByName = "nestedName")
|
||||
Target map(Source source);
|
||||
|
||||
@InheritInverseConfiguration
|
||||
@Mapping(target = "nested.nestedName", source = "name")
|
||||
Source map(Target target);
|
||||
|
||||
@Named("nestedName")
|
||||
default String mapNestedName(Source source) {
|
||||
if ( source == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Nested nested = source.getNested();
|
||||
|
||||
return nested != null ? nested.getNestedName() : null;
|
||||
}
|
||||
|
||||
class Target {
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
class Nested {
|
||||
private String nestedName;
|
||||
|
||||
public String getNestedName() {
|
||||
return nestedName;
|
||||
}
|
||||
|
||||
public void setNestedName(String nestedName) {
|
||||
this.nestedName = nestedName;
|
||||
}
|
||||
}
|
||||
|
||||
class Source {
|
||||
|
||||
private Nested nested;
|
||||
|
||||
public Nested getNested() {
|
||||
return nested;
|
||||
}
|
||||
|
||||
public void setNested(Nested nested) {
|
||||
this.nested = nested;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.ap.test.bugs._3670;
|
||||
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.ProcessorTest;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@IssueKey("3670")
|
||||
@WithClasses(Issue3670Mapper.class)
|
||||
class Issue3670Test {
|
||||
|
||||
@ProcessorTest
|
||||
void shouldCompile() {
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user