Android - How to deserialize xml containing list of objects using Simple api
android, xml-deserialization
Solution
My apologies for taking such a long time to get back at you. In case you haven't figured out the problem by now, I had a little play with your example and managed to find the solution. It's actually pretty straightforward, and you were really close in getting it to work yourself. Please disregard my earlier comment, because that won't take you any closer to solving the issue.
There are two things you need to change to make it work:
First, add `entry="Person"` to the element list in `MyPersons`, such that the result will look like this:
@ElementList(entry="Person", inline=true)
private List<Person> persons;
Second, if you're planning on testing it on the provided xml example, fix up some of the name entries to have a correct closing tag. For example: `<Name>bar</Category>`, which will obviously break the validity of the xml structure. I'm pretty sure though it's just a typo and that the same error isn't present in your live data.
Problem
I need to deserialize an xml response to an object, using simple api. When I deserialize an object, it works just fine, but when I try to deserialize an inline list, I get an exception: org.simpleframework.xml.core.ElementException: Element 'Person' does not have a match in class MyPersons at line 3. would appreciate a clue on what I am doing wrong or a working example for deserializing an inline list with complex objects. Thanks. Attached is a simplified example of my objects: my xml: ``` <Persons> <Person> <Info> <ID>1</ID> <Name>A</Name> </Info> <Address>aaa</Address> <Products> <Product> <Name>foo</Name> <Product>foofoo</Product> </Product> <Product> <Name>bar</Category> <Product>barbar</Product> </Product> </Products> </Person> <Person> <Info> <ID>2</ID> <Name>B</Name> </Info> <Address>bbb</Address> <Products> <Product> <Name>foo2</Name> <Product>foofoo2</Product> </Product> <Product> <Name>bar2</Category> <Product>barbar2</Product> </Product> </Products> </Person> </Persons> ``` my objects: ``` @Root(name="Persons") public class MyPersons { @ElementList(inline=true) private List<Person> persons; } @Root public class Person { @Element private Info Info; @Element(required=false) private String Address; @ElementList private List<Product> Products; public Person(@Element(name="Info") Info Info){ this.Info = Info; //doing some logic } } public class Product { @Element private String Name; @Element private String Product; } @Root public class Info { @Element(required=false) private String ID; @Element private String Name; } ```