#2743 BeanMappingOptions should not be inherited for forged methods

This commit is contained in:
Filip Hrisafov 2022-09-29 22:10:27 +02:00
parent a98986c08e
commit 9d2bed09ca
4 changed files with 105 additions and 3 deletions

View File

@ -54,13 +54,16 @@ public class BeanMappingOptions extends DelegatingOptions {
return options;
}
public static BeanMappingOptions empty(DelegatingOptions delegatingOptions) {
return new BeanMappingOptions( null, Collections.emptyList(), null, delegatingOptions );
}
public static BeanMappingOptions getInstanceOn(BeanMappingGem beanMapping, MapperOptions mapperOptions,
ExecutableElement method, FormattingMessager messager,
TypeUtils typeUtils, TypeFactory typeFactory
) {
if ( beanMapping == null || !isConsistent( beanMapping, method, messager ) ) {
BeanMappingOptions options = new BeanMappingOptions( null, Collections.emptyList(), null, mapperOptions );
return options;
return empty( mapperOptions );
}
Objects.requireNonNull( method );

View File

@ -365,7 +365,7 @@ public class MappingMethodOptions {
options.mappings,
options.iterableMapping,
options.mapMapping,
options.beanMapping,
BeanMappingOptions.empty( options.beanMapping.next() ),
options.enumMappingOptions,
options.valueMappings,
Collections.emptySet(),

View File

@ -0,0 +1,75 @@
/*
* 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._2743;
import org.mapstruct.BeanMapping;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author Filip Hrisafov
*/
@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR)
public interface Issue2743Mapper {
@BeanMapping(ignoreUnmappedSourceProperties = { "number" })
Target map(Source source);
class Source {
private final int number = 10;
private final NestedSource nested;
public Source(NestedSource nested) {
this.nested = nested;
}
public int getNumber() {
return number;
}
public NestedSource getNested() {
return nested;
}
}
class NestedSource {
private final String value;
public NestedSource(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
class Target {
private final NestedTarget nested;
public Target(NestedTarget nested) {
this.nested = nested;
}
public NestedTarget getNested() {
return nested;
}
}
class NestedTarget {
private final String value;
public NestedTarget(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
}

View File

@ -0,0 +1,24 @@
/*
* 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._2743;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;
/**
* @author Filip Hrisafov
*/
@IssueKey("2743")
@WithClasses({
Issue2743Mapper.class
})
class Issue2743Test {
@ProcessorTest
void shouldCompile() {
}
}