使用 XStream 对 Set 的内容进行别名
我在 XStream 中遇到别名问题。
我有一组 String 项目,我想将它们序列化为 XML,如下所示:
<types>
<type>abc</type>
<type>def</type>
</types>
但是,我似乎找不到解决此问题的好方法。我尝试了一个字符串列表,但最终我
<types>
<string>abc</string>
<string>def</string>
</types>
也尝试将字符串放入一个简单的类中,但后来我得到了
<types>
<type>
<aType>abc</aType>
</type>
</types>
其中
是自定义的别名类,aType 是类中的属性,即使用这种方法我得到的级别太多了。我将如何消除额外的级别或简单地用自定义标签名称替换
?
I have a problem with aliasing in XStream.
I've got a set of String items that I would like to serialize to XML like this:
<types>
<type>abc</type>
<type>def</type>
</types>
However, I can't seem to find a good way to solve this. I've tried a list of strings, but then I end up with
<types>
<string>abc</string>
<string>def</string>
</types>
I've also tried putting the String in a simple class, but then I get
<types>
<type>
<aType>abc</aType>
</type>
</types>
where <type>
is the alias of the custom class, and aType is the attribute in the class, i.e I get one level too much using this approach. How would I go about eliminating the extra level or simply substituting the <string>
with a custom tag name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为
List
和列表中的项目指定别名。将会导致
You will need to alias both the
List
and the items in the list.Will result in