I have the following domain structure:
abstract class Person { String name; //with getter and setter }
class Employer extends Person {}
class Employee extends Person {}
class Contract { Person contractor; //with getter and setter }
class PersonDTO implements Serializable { String name; String type; //type == 'Employee' or 'Employer' }
class ContractDTO implements Serializable { PersonDTO contractor; }
Now when I set up this following dozer mapping:
<mapping>
<class-a>Person</class-a>
<class-b>PersonDTO</class-b>
</mapping>
<mapping>
<class-a>Employer</class-a>
<class-b>PersonDTO</class-b>
</mapping>
<mapping>
<class-a>Contract</class-a>
<class-b>ContractDTO</class-b>
</mapping>
My problem concerns the mapping of the field Contract.contractor from B to A because the field Contract.contractor is an abstract class and dozer cannot guess how to instanciate it.
So my question is simple: how can I indicate to dozer that, for the mapping of the field Contract.contractor, it should instantiate an instance of Employer
if type == 'Employer
' and elsewhere Employee
?
Thank you for your help.