ElementListUnion - 简单的XML给人重复的标注为泛型列表对象 [英] ElementListUnion - Simple xml giving duplicate annotation for generic list objects
本文介绍了ElementListUnion - 简单的XML给人重复的标注为泛型列表对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图反序列化使用elementlistunion列表字段
I am trying to deserialize a List field using elementlistunion
Customer.java
@ElementListUnion({ @ElementList(inline = false, type = Thing.class),
@ElementList(inline = false, type = AnotherThing.class) })
List<Object> things = new ArrayList<Object>();
在这里的事和AnotherThing 2 POJO's.But荫得到以下异常
where Thing and AnotherThing are 2 POJO's.But Iam getting the following exception
03-21 18:56:31.940: E/AndroidRuntime(2289): Caused by:
org.simpleframework.xml.core.PersistenceException: Duplicate annotation
of name 'things' on
@org.simpleframework.xml.ElementListUnion(value=
[@org.simpleframework.xml.ElementList(data=false,
empty=true, entry=, inline=false, name=, required=true, type=class
com.data.Thing), @org.simpleframework.xml.ElementList(data=false,
empty=true, entry=, inline=false, name=, required=true, type=class
com.data.AnotherThing)]) on field 'things' java.util.List
com.data.Customer.things
我一直停留在这个一整天了。请帮助。
I have been stuck on this for a whole day now. Please Help.
下面是我的XML响应:
Here is my response xml :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customer>
<address>
<no>122</no>
<street>xxx</street>
</address>
<id>122</id>
<name>James Bond</name>
<things>
<thing>
<val>185</val>
</thing>
<thing>
<val>162</val>
</thing>
</things>
推荐答案
我不知道为什么你试图在ElementsListUnion两班。您可以使用
I don't know why are you trying to make two classes in ElementsListUnion. You can use
@ElementList(inline = false, type = Thing.class)
而不是这个或
@ElementListUnion({ @ElementList(inline = false, type = Thing.class, required = false),
@ElementList(inline = false, type = AnotherThing.class, required = false) })
如果你不每次发送两个元素的类型。
if you don't send two elements types every time.
这篇关于ElementListUnion - 简单的XML给人重复的标注为泛型列表对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文