Castor 列出多态性
我有一个简短的卡斯特问题。我想使用 Castor 映射来编组对象列表。这些对象有两种不同的类型,都扩展同一个抽象基类。我希望它们在 xml 中具有不同的标签,但都添加到同一列表中。他们的领域也略有不同。这可能吗?如果是这样,怎么办? 感谢您的帮助。
I have a quick Castor question. I would like to use Castor mapping to marshal a list of objects. These objects are of two different types, both extending the same abstract base class. I would like them to have different tags in the xml, but both be added to the same list. They also have slightly different fields. Is this possible? If so, how?
Thanks for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然可以编组为 XML。 使用
在列表字段的声明中 ,并为属于列表成员的两个类定义单独的映射。然后,它将使用
map-to
输出不同的 XML 节点名称,并使用每个class
映射来确定不同的内容。您还可以在基类上使用extends 属性,这样您也只需映射基类的成员一次。It's certainly possible to marshal to XML. Use
in the declaration of your list field, and define separate mappings for the two classes that are members of your list. It'll then use the
map-to
to output different XML node names, and eachclass
mapping to determine different content. You can also use theextends
attribute on the base class so you only need to map the members of the base class once, too.