2

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>

4

1 に答える 1

0

ElementsListUnion で 2 つのクラスを作成しようとしている理由がわかりません。使用できます

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

これの代わりに、または

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

毎回 2 つの要素タイプを送信しない場合。

于 2013-04-23T10:29:09.973 に答える