mapstruct

Completely disable automapping in Mapstruct?


I want to disable all auto-mapping in my Mapper and force myself to define all Mapping behavior for the target. Tried

@Mapper(
    componentModel = "spring",
    unmappedTargetPolicy = ReportingPolicy.ERROR
)

but it has 0 effect.


Solution

  • I don't think it is possible; what you are looking for is a class-based function like the BeanMapping#ignoreByDefault property, but this can be set only on the mapper methods and has the drawback that disables also all warnings and error. This from the javadoc:

    Default ignore all mappings. All mappings have to be defined manually. No automatic mapping will take place. No warning will be issued on missing source or target properties.

    Also the annotation @MapperConfig seems not to offer the chanche of disabling the auto-mapping correlated with errors when attributes are not accounted.