Reputation: 2070
I'm using mapstruct to map an object to a DTO. My object has 100 fields that need to be mapped in the DTO, and about 30 that shouldn't be mapped.
How can I ignore the 30 fields without having to write 30 times
@Mapping(source = "fieldtoIgnore", ignore = true)
I'm not looking to ignore the warning, I want to completely prevent mapstruct from mapping some fields
Thank you
Upvotes: 3
Views: 1822
Reputation: 9492
You can define on the mapping method the following annotation:
@BeanMapping(ignoreByDefault = true)
this will make mapstruct to ignore by default all matching fields between the two classes.
Here is a Quotation from Mapstruct documentation regarding this annotation:
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.
and link to the javadoc: http://mapstruct.org/documentation/stable/api/org/mapstruct/BeanMapping.html
Upvotes: 3