How to compare a field with a type in the form of an abstract class with a bulldozer?

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 that I have configured this following bulldozer display:

 <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 is matching the Contract.contractor field from B to A, because the Contract.contractor field is an abstract class, and the dozer cannot guess how to initiate it.

So my question is simple: how can I tell dozer that to map the Contract.contractor field, it must create an instance of Employer if type == 'Employer ' and elsewhere in Employee ?

Thank you for your help.

+4
source share
1 answer

You can do this with the help of tips. Like that:

 <mapping> <class-a>Contract</class-a> <class-b>ContractDTO</class-b> <field> <a>contractor</a> <b>contractor</b> <a-hint>your.package.Employer, your.package.Employee</a-hint> <b-hint>your.DTOpackage.EmployerDTO, your.DTOpackage.EmployeeDTO</b-hint> </field> </mapping> 
0
source

Source: https://habr.com/ru/post/1385865/


All Articles