我想做这样的事情:
ArrayList<CustomObject> objects = new ArrayList<CustomObject>();
...
DozerBeanMapper MAPPER = new DozerBeanMapper();
...
ArrayList<NewObject> newObjects = MAPPER.map(objects, ...);
假设:
<mapping>
<class-a>com.me.CustomObject</class-a>
<class-b>com.me.NewObject</class-b>
<field>
<a>id</a>
<b>id2</b>
</field>
</mapping>
我试过了:
ArrayList<NewObject> holder = new ArrayList<NewObject>();
MAPPER.map(objects, holder);
但是持有者对象是空的。我还尝试更改第二个参数,但没有任何运气......
最佳答案
引用:
"Nested collections are handled automatically, but you are correct that top level collections need to be iterated over. Currently there isn't a more elegant way to handle this."
Someone has figured a way to do it without a looping construct in your code base ,但我认为将它放入您的代码中更容易(并且更具可读性/可维护性)。希望他们能尽快添加此功能。
关于java - 如何在 Dozer 中映射集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1358595/