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
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ private boolean isRedefined(Set<String> redefinedNames, String inheritedName ) {
}

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() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,20 @@ public void shouldMapSomeAdditionalTests2() {
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" );

}
}
Original file line number Diff line number Diff line change
@@ -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

}