如何在Dozer中映射集合 [英] How to map collections in Dozer

查看:1009
本文介绍了如何在Dozer中映射集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做类似的事情:

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);

但持有者对象为空。我还玩了改变第二个参数而没有任何运气...

but the holder object is empty. I also played with changing the second argument without any luck...

推荐答案

引用:


嵌套集合会自动处理
,但你是正确的
,顶级集合需要重复
。目前还有这是
更优雅的方式来处理这个问题。

"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, but I think it's just easier (and more readable/maintainable) to put it in your code. Hopefully they'll add this ability sooner than later.

这篇关于如何在Dozer中映射集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆