简单的XML ElementListUnion - 两个通用列出不准? [英] Simple XML ElementListUnion - two generic lists not allowed?

查看:196
本文介绍了简单的XML ElementListUnion - 两个通用列出不准?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想desrialize通过简单的架构的XML。我有两个表的类型将只在运行时才能知道。所以我用@ElementListUnion。

I am trying to desrialize an xml through simple framework. I have two lists whose types will be known only at runtime. So I used @ElementListUnion.

Customer.java

@ElementListUnion({@ElementList(inline = true,type=Thing.class),@ElementList(inline = true,type=AnotherThing.class)})
List<Object> things;


@ElementListUnion({@ElementList(inline = true,type=Thing.class),@ElementList(inline = true,type=AnotherThing.class)})
List<Object> anotherthings ;

但即时得到以下异常

But Im getting the following exception

03-20 19:36:20.534: E/AndroidRuntime(2764): Caused by:  
 org.simpleframework.xml.core.PersistenceException: Duplicate annotation of name 
'thing' on @org.simpleframework.xml.ElementListUnion(value=
[@org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=true,
  name=, 
required=true, type=class com.data.Thing),  
 @org.simpleframework.xml.ElementList(data=false,
 empty=true, entry=, inline=true, name=, required=true, type=class 
 com.data.AnotherThing)])
 on field 'things' java.util.List com.data.Customer.things

请帮忙。

推荐答案

您还没有设置为输入的值,那么简单的不能决定你是哪个班使用。在这里看到:

You haven't set a value for entry, so Simple can't decide which class you are using. See here:

@Root(name = "Customer")
public class Customer
{
    @ElementListUnion(
    {
        @ElementList(entry = "thingValue", inline = true, type = Thing.class),
        @ElementList(entry = "anotherThingValue", inline = true, type = AnotherThing.class)
    })
    List<Object> things;


    @ElementListUnion(
    {
        @ElementList(entry = "thingValue", inline = true, type = Thing.class),
        @ElementList(entry = "anotherThingValue", inline = true, type = AnotherThing.class)
    })
    List<Object> anotherthings;

}

每个 @ElementList 需要输入,这就是它用于该元素的标记:

Each @ElementList requires an entry, thats the tag which is used for the element:

<Customer>
   <thingValue>...<thingValue/>                 <!-- That's a 'Thing' -->
   <anotherThingValue>...<anotherThingValue/>   <!-- That's an 'AnotherThing' -->
</Customer>

但要舒尔你不命名输入象类,所以项=东西可能会失败。

But make shure you dont name the entry like the class, so entry = "thing" may fail.

这篇关于简单的XML ElementListUnion - 两个通用列出不准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆