Excluding fields in Dozer mapping

Prateek Singh picture Prateek Singh · Jul 16, 2015 · Viewed 7.8k times · Source

Is there a way to exclude multiple fields in Dozer, when source and target classes are the same?

I am using it like this:

<mapping map-null="false" wildcard="true">
    <class-a>com.abc</class-a>
    <class-b>com.abc</class-b>
    <field-exclude>
        <a>field1</a> 
        <b>field1</b> 
    </field-exclude>
    <field-exclude>
        <a>field2</a> 
        <b>field2</b> 
    </field-exclude> ....                                                   
</mapping>

It seems so funny to write same name when it's known that it'll always be same for all... Is there any alternative?

Answer

naXa picture naXa · Jan 24, 2017

I found this post in Google, but I configure Dozer via annotations so the existing answer didn't help me.

In order to exclude a field from mapping via annotations use @Mapping("this") on the field.

Source: Dozer, how to ignore a field with annotation