mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
parent
2fede3583d
commit
c0d88f86bf
@ -238,10 +238,10 @@ public class MappingMethodOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean elementsAreContainedIn( String redefinedName, 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
|
// 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
|
// 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() ) {
|
if ( redefinedName.length() > inheritedName.length() ) {
|
||||||
// redefined.lenght() > inherited.length(), first following character should be separator
|
// redefined.lenght() > inherited.length(), first following character should be separator
|
||||||
return '.' == redefinedName.charAt( inheritedName.length() );
|
return '.' == redefinedName.charAt( inheritedName.length() );
|
||||||
|
@ -64,4 +64,20 @@ public class Issue2101Test {
|
|||||||
assertThat( target.value3 ).isEqualTo( "test" );
|
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" );
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user