简体   繁体   English

Java推土机-要列出的元素A

[英]Java Dozer - Element A to List<B>

I need to map two very similar complex objects. 我需要映射两个非常相似的复杂对象。

For instance, I want to map class A and B which are (let's say) houses. 例如,我要映射A类和B类(假设是房屋)。 Class A is designed with one door only. A级仅设计有一个门。 (which is a class of its own, with its fields) Class B is designed with a list of doors. (这是它自己的一个类,带有其字段)B类的设计带有一系列门。 (which is a mirror-like of the other door class) (类似于其他门类的镜子)

There will always be only one door in the house, but I don't want to change Class A & B. 房子里总是只有一扇门,但我不想更改A和B类。

'til Today, I just can't map it with Dozer. 直到今天,我都无法用推土机来绘制它。 I tried things like: 我尝试过类似的事情:

<a>door</a>
<b>doors[0]</b>
<b-hint>path.to.doorB</b-hint>

Each time I get something like "no write method for B". 每次我得到类似“ B的无写方法”的信息。

I can call the dozer conversion in java at the door level, but well it's such a pain in the.. And well the idea of using Dozer was so I could simplify the conversion process. 我可以在门级用Java调用推土机转换,但这确实很麻烦。而且,使用推土机的想法是为了简化转换过程。

(Moreover I do have a lot of cases like this one) (此外,我确实有很多这样的情况)

Help would be greatly appreciated, with all of my gratitude given to whoever helps me on this one :). 非常感谢您的帮助,在此感谢所有帮助我的人:)。

Thanks in advance guys! 在此先感谢大家!

如果不想像@Raphael所说的那样通过添加setter来修改自动生成的类,则总是可以编写一个工厂方法来映射两个非常相似的复杂对象。

this functionality is already implemented by dozer what you have to do is to specify in the field mapping that you are going to map an element of the array field of class A to field in class B and it is done like this: 推土机已经实现了此功能,您需要做的是在字段映射中指定要将A类的数组字段的元素映射到B类的字段,并且这样做是这样的:

<mapping>
    <class-a>A</class-a>
    <class-b>B</class-b>
    <field>
        <a>valueString[0]</a>
        <b>valueInteger</b>
    </field>
</mapping>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM