* #2139 reproducer

* #2139 solution

* #2139 license
This commit is contained in:
Sjaak Derksen 2020-07-05 14:41:08 +02:00 committed by Filip Hrisafov
parent 2fede3583d
commit c0d88f86bf
3 changed files with 56 additions and 2 deletions

View File

@ -238,10 +238,10 @@ public class MappingMethodOptions {
}
private boolean elementsAreContainedIn( String redefinedName, String inheritedName ) {
if ( redefinedName.startsWith( inheritedName ) ) {
if ( inheritedName != null && redefinedName.startsWith( inheritedName ) ) {
// it is possible to redefine an exact matching source name, because the same source can be mapped to
// multiple targets. It is not possible for target, but caught by the Set and equals methoded in
// MappingOptions
// MappingOptions. SourceName == null also could hint at redefinition
if ( redefinedName.length() > inheritedName.length() ) {
// redefined.lenght() > inherited.length(), first following character should be separator
return '.' == redefinedName.charAt( inheritedName.length() );

View File

@ -64,4 +64,20 @@ public class Issue2101Test {
assertThat( target.value3 ).isEqualTo( "test" );
}
@Test
@WithClasses(Issue2102IgnoreAllButMapper.class)
public void shouldApplyIgnoreAllButTemplateOfMethod1() {
Issue2102IgnoreAllButMapper.Source source = new Issue2102IgnoreAllButMapper.Source();
source.value1 = "value1";
source.value2 = "value2";
Issue2102IgnoreAllButMapper.Target target = Issue2102IgnoreAllButMapper.INSTANCE.map1( source );
assertThat( target.value1 ).isEqualTo( "value1" );
target = Issue2102IgnoreAllButMapper.INSTANCE.map2( source );
assertThat( target.value1 ).isEqualTo( "value2" );
}
}

View File

@ -0,0 +1,38 @@
/*
* 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._2101;
import org.mapstruct.BeanMapping;
import org.mapstruct.InheritConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
public interface Issue2102IgnoreAllButMapper {
Issue2102IgnoreAllButMapper INSTANCE = Mappers.getMapper( Issue2102IgnoreAllButMapper.class );
@BeanMapping( ignoreByDefault = true )
@Mapping(target = "value1") // but do map value1
Target map1(Source source);
@InheritConfiguration
@Mapping(target = "value1", source = "value2" )
Target map2(Source source);
//CHECKSTYLE:OFF
class Source {
public String value1;
public String value2;
}
class Target {
public String value1;
}
//CHECKSTYLE:ON
}