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;
}
Personhas a proper root element. I would start with removing@ElementList(inline=true). Here are a couple of examples worth looking at: deserializing a list & deserializing a list inline.