mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#2743 BeanMappingOptions should not be inherited for forged methods
This commit is contained in:
parent
a98986c08e
commit
9d2bed09ca
@ -54,13 +54,16 @@ public class BeanMappingOptions extends DelegatingOptions {
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BeanMappingOptions empty(DelegatingOptions delegatingOptions) {
|
||||||
|
return new BeanMappingOptions( null, Collections.emptyList(), null, delegatingOptions );
|
||||||
|
}
|
||||||
|
|
||||||
public static BeanMappingOptions getInstanceOn(BeanMappingGem beanMapping, MapperOptions mapperOptions,
|
public static BeanMappingOptions getInstanceOn(BeanMappingGem beanMapping, MapperOptions mapperOptions,
|
||||||
ExecutableElement method, FormattingMessager messager,
|
ExecutableElement method, FormattingMessager messager,
|
||||||
TypeUtils typeUtils, TypeFactory typeFactory
|
TypeUtils typeUtils, TypeFactory typeFactory
|
||||||
) {
|
) {
|
||||||
if ( beanMapping == null || !isConsistent( beanMapping, method, messager ) ) {
|
if ( beanMapping == null || !isConsistent( beanMapping, method, messager ) ) {
|
||||||
BeanMappingOptions options = new BeanMappingOptions( null, Collections.emptyList(), null, mapperOptions );
|
return empty( mapperOptions );
|
||||||
return options;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Objects.requireNonNull( method );
|
Objects.requireNonNull( method );
|
||||||
|
@ -365,7 +365,7 @@ public class MappingMethodOptions {
|
|||||||
options.mappings,
|
options.mappings,
|
||||||
options.iterableMapping,
|
options.iterableMapping,
|
||||||
options.mapMapping,
|
options.mapMapping,
|
||||||
options.beanMapping,
|
BeanMappingOptions.empty( options.beanMapping.next() ),
|
||||||
options.enumMappingOptions,
|
options.enumMappingOptions,
|
||||||
options.valueMappings,
|
options.valueMappings,
|
||||||
Collections.emptySet(),
|
Collections.emptySet(),
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user