Ivancodescratch
Ivancodescratch

Reputation: 405

Dozer mapping on objects to

i have an two seperate objects to map:

Class A {
    List<AA> listAA;
    // get set methods...
}

Class B{
    C objectC = new C();
    // get set methods...
}

Class C{
    List<CC> listCC;
    // get set methods...
}

Class AA{
    String aa;
    // get set methods...
}

Class CC{
     String cc;
    // get set methods...
}

So i want to map listAA to listCC that inside of C. With C has B as a parents.

I try describing it as data structure:

a.listAA -> b.c.listCC 

So far i've tried:

<mappings>
    <mapping>
        <class-a>mypackages.A</class-a>
        <class-b>mypackages.B</class-b>
        <field>
            <a>listAA</a>
            <b>objectC.listCC</b>
            <b-hint>mypackages.CC</b-hint>
        <field>
    </mapping>

    <mapping>
        <class-a>mypackages.AA</class-a>
        <class-b>mypackages.CC</class-b>
        <field>
            <a>aa</a>
            <b>cc</b>
        <field>
    </mapping>
</mappings>

I think is that dozer didn't know

objectC.listCC

as an list with in Object. Instead tried to find attributes that called 'objectC.listCC'.

And it throws

 NullPointerException
    at org.dozer.util.ReflectionsUtils.invoke(ReflectionsUtils)
    ...

Does any one knows to how to solve this.

Regards

Ivan

PS: I hope i was describeing it clearly

Upvotes: 1

Views: 155

Answers (1)

Ivancodescratch
Ivancodescratch

Reputation: 405

Sometimes you have to go out and forget for searching the answers and come again with a fresh head. I extend the mapping configuration into three parts. Because dozer are not able to map object to a grand child object. So you have to do like chain mapping:

 <mappings>
    <mapping>
        <class-a>mypackages.A</class-a>
        <class-b>mypackages.B</class-b>
        <field map-id="listAAToObjectC">
            <a>listAA</a>
            <b>objectC</b>
            <b-hint>mypackages.C</b-hint>
        <field>
    </mapping>
    <mapping map-id="listAAToObjectC">
        <class-a>mypackages.A</class-a>
        <class-b>mypackages.C</class-b>
        <field map-id="listToList">
            <a>listAA/a>
            <b>listCC</b>
        <field>
    </mapping>
    <mapping map-id="listToList">
        <class-a>mypackages.AA</class-a>
        <class-b>mypackages.CC</class-b>
        <field>
            <a>aa</a>
            <b>cc</b>
        <field>
    </mapping>
</mappings>

Upvotes: 1

Related Questions