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
|
||||
|
||||
* 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
|
||||
|
||||
### Documentation
|
||||
|
@ -1764,10 +1764,6 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
if ( mappingReferences.isForForgedMethods() ) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,9 @@ import org.mapstruct.factory.Mappers;
|
||||
@Mapper(
|
||||
unmappedTargetPolicy = ReportingPolicy.IGNORE,
|
||||
unmappedSourcePolicy = ReportingPolicy.ERROR)
|
||||
public interface SourceTargetMapper {
|
||||
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
|
||||
public interface ErroneousSourceTargetMapperWithIgnoreByDefault {
|
||||
ErroneousSourceTargetMapperWithIgnoreByDefault INSTANCE = Mappers.getMapper(
|
||||
ErroneousSourceTargetMapperWithIgnoreByDefault.class );
|
||||
|
||||
@Mapping(source = "one", target = "one")
|
||||
@BeanMapping(ignoreByDefault = true)
|
@ -18,8 +18,17 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutco
|
||||
public class IgnoreByDefaultSourcesTest {
|
||||
|
||||
@ProcessorTest
|
||||
@WithClasses({ SourceTargetMapper.class, Source.class, Target.class })
|
||||
public void shouldSucceed() {
|
||||
@WithClasses({ ErroneousSourceTargetMapperWithIgnoreByDefault.class, Source.class, Target.class })
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = ErroneousSourceTargetMapperWithIgnoreByDefault.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 23,
|
||||
message = "Unmapped source property: \"other\".")
|
||||
}
|
||||
)
|
||||
public void shouldRaiseErrorDueToNonIgnoredSourcePropertyWithBeanMappingIgnoreByDefault() {
|
||||
}
|
||||
|
||||
@ProcessorTest
|
||||
|
Loading…
x
Reference in New Issue
Block a user