【问题标题】:ElementListUnion - Simple xml giving duplicate annotation for generic list objectsElementListUnion - 为通用列表对象提供重复注释的简单 xml
【发布时间】:2013-03-21 19:03:28
【问题描述】:

我正在尝试使用 elementlistunion 反序列化 List 字段

Customer.java

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

Thing 和 AnotherThing 是 2 个 POJO。但我得到以下异常

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

我已经坚持了一整天了。请帮忙。

这是我的回复 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>

【问题讨论】:

标签: android generics deserialization unmarshalling simple-framework


【解决方案1】:

我不知道你为什么要在 ElementsListUnion 中创建两个类。你可以使用

@ElementList(inline = false, type = Thing.class) 

而不是这个或

 @ElementListUnion({ @ElementList(inline = false, type = Thing.class, required = false),
        @ElementList(inline = false, type = AnotherThing.class, required = false) }) 

如果您不是每次都发送两种元素类型。

【讨论】:

    猜你喜欢
    • 2013-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 1970-01-01
    相关资源
    最近更新 更多