24996

ElementListUnion - Simple xml giving duplicate annotation for generic list objects

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>();

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.

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>

Answer1:

I don't know why are you trying to make two classes in ElementsListUnion. You can use

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

instead of this or

@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.

Recommend

  • inflate a button using xml to style
  • Create JSON file with deep array
  • Failed to create SQLite DB in my Samsung y duos device in Android?
  • Spring @Controller and custom MethodNameResolver
  • VerifyError in web-service operation using SOAP only in Android 4.2?
  • SDK 25.1.0 crash on CommitNow when call within onBackStackChanged(). Google Bug?
  • Get Amazon Access Key & Secret Key from IAM Username in Java
  • java.lang.StackOverflowError error shows on making json array object?
  • Karate vs Spock
  • Python - Creating a dictionary using List
  • Hibernate with Primary Key in PostgreSQL with camelCase Format
  • Problem obtaining entities with uniqueidentifier primary key
  • Sorting a HashMap, while keeping duplicates
  • Recreate Apple Watch fitness tracker ‘progress’ bar - gradient on CAShapeLayer stroke
  • How to apply async task into this
  • Success handler not working after Symfony2 login
  • Angular5 Service Worker update(SWUpdate) not detecting on firefox. Working on chrome
  • What is a structure of u-boot flash file? ( ARM versatile pb )
  • JPA/EclipseLink Returning No Results
  • Pyglet uses too much cpu
  • How can I tell Phusion Passenger which python to use?
  • jQuery timepicker 'Object does not support this property or method'
  • INSERT EXEC Statement cannot be nested [duplicate]
  • get_absolute_url with parameters
  • SPARQL date range
  • drawing random circles, storing their coorindates in an array
  • Magento site down due to mysql error General error: 1030 Got error -1 from storage engine
  • Primefaces ManyCheckbox inside ui:repeat calls setter method only for last loop
  • Angular2 component view does not update on value change via method
  • CakePHP ACL tutorial initDB function warnings
  • SetUp method failed while running tests from teamcity
  • Understanding cpu registers
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • How do I use LINQ to get all the Items that have a particular SubItem?