Deep Property Mapping

It is possible to map deep properties. An example would be when you have an object with a String property. Your other object has a String property but it is several levels deep within the object graph. In the example below the DestDeepObj has nested attributes within the object graph that need to be mapped. Type hints are supported for deep field mappings. The attributes copy-by-reference, type=one-way, and relationship-type can also be used.

<mapping>
    <class-a>com.github.dozermapper.core.vo.deep.SrcDeepObj</class-a>
    <class-b>com.github.dozermapper.core.vo.deep.DestDeepObj</class-b>
    <field>
        <a>srcNestedObj.src1</a>
        <b>dest1</b>
    </field>
    <field>
        <a>srcNestedObj.src2</a>
        <b>dest2</b>
    </field>
    <field>
        <a>srcNestedObj.srcNestedObj2.src5</a>
        <b>dest5</b>
    </field>
    <field>
        <!-- java.util.List to java.util.List -->
        <a>srcNestedObj.hintList</a>
        <b>hintList</b>
        <a-hint>java.lang.String</a-hint>
        <b-hint>java.lang.Integer</b-hint>
    </field>
    <field>
        <a>srcNestedObj.hintList2</a>
        <b>hintList2</b>
        <a-hint>com.github.dozermapper.core.vo.TheFirstSubClass</a-hint>
        <b-hint>com.github.dozermapper.core.vo.TheFirstSubClassPrime</b-hint>
    </field>
    <field copy-by-reference="true">
        <a>srcNestedObj.hintList3</a>
        <b>hintList3</b>
    </field>
</mapping>

Deep Indexed Mapping

Indexed mapping within deep mapping is supported.

<field>
    <a>offSpringName</a>
    <b>pets[1].offSpring[2].petName</b>
</field>

Destination Hints are NOT required if the indexed collection is an Array or if you are using jdk 1.5 Generics. Dozer is able to automatically determine the property type for these use cases. But you will need to provide hints if the data types are not Arrays or if you are not using Generics. This is required so that Dozer knows what types of dest objects to create while it traverses the deep field mapping.

The following is an example of using hints…​..

<field>
    <a>someField</a>
    <b>someList[1].someOtherList[0].someOtherField</b>
    <b-deep-index-hint>
        com.github.dozermapper.core.vo.TestObject, com.github.dozermapper.core.vo.AnotherTestObject
    </b-deep-index-hint>
</field>

results matching ""

    No results matching ""