如何使用推土机将类型字段映射为抽象类?
我有以下域结构:
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; }
现在,当我设置以下推土机映射时:
<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>
我的问题涉及字段 Contract.contractor 从 B 到 A 的映射,因为字段 Contract.contractor 是一个抽象类,推土机无法猜测如何实例化它。
所以我的问题很简单:我如何向推土机指示,对于字段 Contract.contractor 的映射,如果 type == 'Employer
,它应该实例化 Employer
的实例>' 以及其他Employee
?
感谢您的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过提示来完成此操作。
有点像这样:
You can do this with hints.
Somewhat like this: