简体   繁体   中英

Exlude field - Mapping with Dozer

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.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM