mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3574 Respect only explicit mappings but fail on unmapped source fields
* #3574 Respect only explicit mappings but fail on unmapped source fields This reverts #2560, because we've decided that `@BeanMapping(ignoreByDefault = true)` should only be applied to target properties and not to source properties. Source properties are anyway ignored, the `BeanMapping#unmappedSourcePolicy` should be used to control what should happen with unmapped source policy
This commit is contained in:
parent
babb9dedd9
commit
69371708ee
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
### Enhancements
|
### Enhancements
|
||||||
|
|
||||||
|
* Breaking change:g (#3574) -
|
||||||
|
This reverts #2560, because we've decided that `@BeanMapping(ignoreByDefault = true)` should only be applied to target properties and not to source properties.
|
||||||
|
Source properties are ignored anyway, the `BeanMapping#unmappedSourcePolicy` should be used to control what should happen with unmapped source policy
|
||||||
|
|
||||||
### Bugs
|
### Bugs
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
@ -1764,10 +1764,6 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
|||||||
if ( mappingReferences.isForForgedMethods() ) {
|
if ( mappingReferences.isForForgedMethods() ) {
|
||||||
return ReportingPolicyGem.IGNORE;
|
return ReportingPolicyGem.IGNORE;
|
||||||
}
|
}
|
||||||
// If we have ignoreByDefault = true, unprocessed source properties are not an issue.
|
|
||||||
if ( method.getOptions().getBeanMapping().isignoreByDefault() ) {
|
|
||||||
return ReportingPolicyGem.IGNORE;
|
|
||||||
}
|
|
||||||
return method.getOptions().getBeanMapping().unmappedSourcePolicy();
|
return method.getOptions().getBeanMapping().unmappedSourcePolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,9 @@ import org.mapstruct.factory.Mappers;
|
|||||||
@Mapper(
|
@Mapper(
|
||||||
unmappedTargetPolicy = ReportingPolicy.IGNORE,
|
unmappedTargetPolicy = ReportingPolicy.IGNORE,
|
||||||
unmappedSourcePolicy = ReportingPolicy.ERROR)
|
unmappedSourcePolicy = ReportingPolicy.ERROR)
|
||||||
public interface SourceTargetMapper {
|
public interface ErroneousSourceTargetMapperWithIgnoreByDefault {
|
||||||
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
|
ErroneousSourceTargetMapperWithIgnoreByDefault INSTANCE = Mappers.getMapper(
|
||||||
|
ErroneousSourceTargetMapperWithIgnoreByDefault.class );
|
||||||
|
|
||||||
@Mapping(source = "one", target = "one")
|
@Mapping(source = "one", target = "one")
|
||||||
@BeanMapping(ignoreByDefault = true)
|
@BeanMapping(ignoreByDefault = true)
|
@ -18,8 +18,17 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutco
|
|||||||
public class IgnoreByDefaultSourcesTest {
|
public class IgnoreByDefaultSourcesTest {
|
||||||
|
|
||||||
@ProcessorTest
|
@ProcessorTest
|
||||||
@WithClasses({ SourceTargetMapper.class, Source.class, Target.class })
|
@WithClasses({ ErroneousSourceTargetMapperWithIgnoreByDefault.class, Source.class, Target.class })
|
||||||
public void shouldSucceed() {
|
@ExpectedCompilationOutcome(
|
||||||
|
value = CompilationResult.FAILED,
|
||||||
|
diagnostics = {
|
||||||
|
@Diagnostic(type = ErroneousSourceTargetMapperWithIgnoreByDefault.class,
|
||||||
|
kind = Kind.ERROR,
|
||||||
|
line = 23,
|
||||||
|
message = "Unmapped source property: \"other\".")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public void shouldRaiseErrorDueToNonIgnoredSourcePropertyWithBeanMappingIgnoreByDefault() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ProcessorTest
|
@ProcessorTest
|
||||||
|
Loading…
x
Reference in New Issue
Block a user