Reputation: 6270
I want to exclude a field using Dozer like this :
<mapping>
<class-a>com.core.model.Model</class-a>
<class-b>com.core.model.ModelIS</class-b>
<field>
<a>person</a>
<b>person</b>
<a-hint>com.core.Person</a-hint>
<b-hint>com.core.PersonIS</b-hint>
</field>
<field-exclude>
<a>age</a>
<b>age</b>
</field-exclude>
</mapping>
So the class Model contains a Person object and the Person has an age object, how can I exclude age from this mapping ? Thanks in advance.
Upvotes: 3
Views: 6838
Reputation: 24590
<field-exclude>
is the correct approach but it works on the mapping it is applied to, in this case the model classes.
If the model classes had an age
object then (given your mapping) it would have been excluded. But the age
object is deeper in the object tree, it's on the person fields within the models, so it must be applied when the person fields are mapped.
Replace your mapping with the following one and it should work:
<mapping>
<class-a>com.core.model.Model</class-a>
<class-b>com.core.model.ModelIS</class-b>
<field>
<a>person</a>
<b>person</b>
<a-hint>com.core.Person</a-hint>
<b-hint>com.core.PersonIS</b-hint>
</field>
</mapping>
<mapping>
<class-a>com.core.Person</class-a>
<class-b>com.core.PersonIS</class-b>
<field-exclude>
<a>age</a>
<b>age</b>
</field-exclude>
</mapping>
Upvotes: 8