这是一个可能的解决方案,希望对您有所帮助:
类注释Order
:
@Root(name="order")
public class Order
{
@Attribute(name="id", required=true)
private int id;
@Element(name="name", required=true)
private String name;
public Order(int id, String name)
{
this.id = id;
this.name = name;
}
public Order() { }
// Getter / Setter
}
Example
类,包含列表:
@Root(name="elementList")
public class Example
{
@ElementList(required=true, inline=true)
private List<Order> list = new ArrayList<>();
// ...
}
这是一些用于阅读您的代码的代码:
Serializer ser = new Persister();
Example example = ser.read(Example.class, file); // file = your xml file
// 'list' now contains all your Orders