#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:
Filip Hrisafov 2024-07-06 10:31:32 +02:00 committed by GitHub
parent babb9dedd9
commit 69371708ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 8 deletions

View File

@ -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

View File

@ -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();
}

View File

@ -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)

View File

@ -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