mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#1552 Stop processing source parameters for unprocessed defined properties when a mapping is found
This commit is contained in:
parent
10f855fa9e
commit
04576de1d1
@ -318,6 +318,8 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
|||||||
unprocessedSourceProperties.remove( propertyName );
|
unprocessedSourceProperties.remove( propertyName );
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
propertyMappings.add( propertyMapping );
|
propertyMappings.add( propertyMapping );
|
||||||
|
// If we found a mapping for the unprocessed property then stop
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 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._1552;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
import org.mapstruct.Mappings;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface Issue1552Mapper {
|
||||||
|
|
||||||
|
Issue1552Mapper INSTANCE = Mappers.getMapper( Issue1552Mapper.class );
|
||||||
|
|
||||||
|
@Mappings({
|
||||||
|
@Mapping(target = "first.value", constant = "constant"),
|
||||||
|
@Mapping(target = "second.value", source = "sourceTwo")
|
||||||
|
})
|
||||||
|
Target twoArgsWithConstant(String sourceOne, String sourceTwo);
|
||||||
|
|
||||||
|
@Mappings({
|
||||||
|
@Mapping(target = "first.value", expression = "java(\"expression\")"),
|
||||||
|
@Mapping(target = "second.value", source = "sourceTwo")
|
||||||
|
})
|
||||||
|
Target twoArgsWithExpression(String sourceOne, String sourceTwo);
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* 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._1552;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mapstruct.ap.testutil.IssueKey;
|
||||||
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
|
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@WithClasses({
|
||||||
|
Issue1552Mapper.class,
|
||||||
|
Target.class
|
||||||
|
})
|
||||||
|
@RunWith(AnnotationProcessorTestRunner.class)
|
||||||
|
@IssueKey("1552")
|
||||||
|
public class Issue1552Test {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCompile() {
|
||||||
|
Target target = Issue1552Mapper.INSTANCE.twoArgsWithConstant( "first", "second" );
|
||||||
|
|
||||||
|
assertThat( target ).isNotNull();
|
||||||
|
assertThat( target.getFirst() ).isNotNull();
|
||||||
|
assertThat( target.getFirst().getValue() ).isEqualTo( "constant" );
|
||||||
|
assertThat( target.getSecond() ).isNotNull();
|
||||||
|
assertThat( target.getSecond().getValue() ).isEqualTo( "second" );
|
||||||
|
|
||||||
|
|
||||||
|
target = Issue1552Mapper.INSTANCE.twoArgsWithExpression( "third", "fourth" );
|
||||||
|
|
||||||
|
assertThat( target ).isNotNull();
|
||||||
|
assertThat( target.getFirst() ).isNotNull();
|
||||||
|
assertThat( target.getFirst().getValue() ).isEqualTo( "expression" );
|
||||||
|
assertThat( target.getSecond() ).isNotNull();
|
||||||
|
assertThat( target.getSecond().getValue() ).isEqualTo( "fourth" );
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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._1552;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
public class Target {
|
||||||
|
private Inner first;
|
||||||
|
private Inner second;
|
||||||
|
|
||||||
|
public Inner getFirst() {
|
||||||
|
return first;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirst(Inner first) {
|
||||||
|
this.first = first;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Inner getSecond() {
|
||||||
|
return second;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecond(Inner second) {
|
||||||
|
this.second = second;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Inner {
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user