Roshan
Roshan

Reputation: 79

Dozer - mapping based on condition

Hi i am creating dozer bean mapping xml to convert from one object to another object.Now i need to map these bean based on condition. For example:

if(A == "Static")
  <field>
        <a>A</a>
        <b>T</b>
    </field>
else if (A == "Dynamic")
   <field>
        <a>A</a>
        <b>D</b>
    </field>

Does dozer support this kind of conditional mapping ? Kindly let me know what is the best way to achieve this ? Thanks in Advance !!

Upvotes: 1

Views: 3451

Answers (2)

Daniel
Daniel

Reputation: 564

There is also ModelMapper that implements a conditional mapping. Have a look here.

Upvotes: 0

Ray
Ray

Reputation: 3959

No, Dozer cannot map based on such a condition. In fact this was precisely the reason why my company developed its own version of Dozer, to be able to apply more conditional cases.

I think what you're looking for is the CustomConverter feature of Dozer, which allows you to specify the condition with a Java class. Implement the CustomConverter class, and give the full path of the Java class in the xml.

Upvotes: 1

Related Questions