Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEXT_RELEASE_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,13 @@ private GroupedTargetReferences groupByTargetReferences( ) {
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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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() {
}
}