Dozer:深度映射不起作用
简单的问题:我正在使用 Dozer 在两个不同的类之间进行映射。在我的目标类(本例中为 A)中,我有一个字段,它是 Name
对象的实例。该对象有两个字符串(姓氏和名字)。这些字符串是通过输入字符串列表并用分隔符将它们连接在一起来构建的。在我的源类(B)中,我有两个列表(姓氏和名字)。所有列表仅包含字符串。
我的推土机映射看起来像:
<mapping>
<class-a>A</class-a>
<class-b>B</class-b>
<field>
<a is-accessible="true" >name.lastNames</a>
<b>lastNames</b>
</field>
<field>
<a is-accessible="true">name.firstNames</a>
<b>firstNames</b>
</field>
</mapping>
但是,当使用上述配置时,我得到以下异常:
org.dozer.MappingException: No such field found class A.name.lastNames
有谁知道它是否是:
- 甚至可以引用字段 以这样的方式?
- 一个可能的 解决我做错的事情 这里?
完整地说:两个列表的 Name 对象上都定义了 getter 和 setter,但是我还没有在 A 类本身上编写 getter 和 setter。
Quick question: I'm using Dozer to make mappings between two different classes. In my destination class (A in this example), I have a field which is an instance of a Name
object. This object has two strings (last- and firstNames). These strings are build by inputting a list of strings and joining them together with a separator. In my source class(B) I have two lists (last- and firstNames). All lists contain only strings.
My dozer mapping looks like:
<mapping>
<class-a>A</class-a>
<class-b>B</class-b>
<field>
<a is-accessible="true" >name.lastNames</a>
<b>lastNames</b>
</field>
<field>
<a is-accessible="true">name.firstNames</a>
<b>firstNames</b>
</field>
</mapping>
However, when using the above configuration, I get the following exception:
org.dozer.MappingException: No such field found class A.name.lastNames
Does anyone know if it is:
- even possible to reference a field
in such a manner? - a possible
solution to what I'm doing wrong
here?
To be complete: there are getters and setters defined on the Name object for both lists, however I have not written getters and setters on class A itself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现无法将深度映射与 is-accessible 属性结合起来。为该类编写自定义映射器就可以解决问题。
Found out it's not possible to combine deep mapping with the
is-accessible
attribute. Writing a custom mapper for the class does the trick.