[英]Xstream: How to deserialize Xml with array
我有一个带有重复数组元素的xml,如何反序列化呢?
<root>
<values>
<val1>afa</val1>
<val2>asgfasg</val2>
</values>
<values>
<val1>hkjvlk</val1>
<val2>sdsdgsdg</val2>
</values>
...
</root>
XStream xstream = new XStream(new DomDriver());
xstream.alias("values", Inventory.class);
InventoryResult inventory = (InventoryResult) xstream.fromXML(data.toString());
&
public class InventoryResult {
private Inventory values;
}
我已经尝试了List,Inventory [],但它们都没有用。
首先,这只是整个xml doc的一部分吗? 如是
<root>
<values>
<val1>afa</val1>
</values>
<values>
<val2>hkjvlk</val2>
</values>
</root>
这是序列化的形式
values [] root = {new values("afa", null), new values(null, "hkjvlk")};
其中Class值看起来像这样
class values{
String val1;
String val2;
public values (String str, String str1){
val1 = str;
val2 = str1;
}
}
我建议编写自己的转换器: http : //x-stream.github.io/converter-tutorial.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.