我需要使用简单的 api 反序列化对对象的 xml 响应。当我反序列化一个对象时,它工作得很好,但是当我尝试反序列化一个内联列表时,我得到一个异常:org.simpleframework.xml.core.ElementException: Element 'Person' does not have a match in class MyPersons at line 3.
将不胜感激我做错了什么的线索或反序列化具有复杂对象的内联列表的工作示例。
谢谢。
附件是我的对象的简化示例:
我的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>
我的对象:
@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;
}