MapStruct ignore automatically unmapped properties

前端 未结 2 2088
执念已碎
执念已碎 2020-12-09 02:24

I am using MapStruct with big models (more than 50 fields) shared between different business use cases in my code. Depending on the entry point, some properties will be mapp

相关标签:
2条回答
  • 2020-12-09 02:39

    For ignore automapping MapStruct 1.3.0.Final Reference Guide:

    By means of the @BeanMapping(ignoreByDefault = true) the default behavior will be explicit mapping, meaning that all mappings have to be specified by means of the @Mapping and no warnings will be issued on missing target properties.

    @BeanMapping(ignoreByDefault = true)
    OneObj map(TwoObj two);
    
    0 讨论(0)
  • 2020-12-09 02:56

    You can set the "unmapped target policy" on the @Mapper level or via @MapperConfig to share a setting across several mappers:

    @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
    public interface MyMapper {}
    
    0 讨论(0)
提交回复
热议问题