我想用 SimpleFramework xml 序列化一个对象列表。 我在普通类上成功了,但在对象列表上却没有。
我找不到用对象列表来完成它的好语法。
List< Shop > shop = new Persister().read(List<Shop>.class, data);
List< Shop >.class
不工作
谢谢
最佳答案
不可能直接这样做;使用 @ElementList相反。
这是一个例子:
店铺类
@Default // Or customize as you need
public class Shop
{
private String name;
public Shop(String name)
{
this.name = name;
}
private Shop() { /* Required default ctor */ }
// ...
}
列表示例
这只是列表的包装器。
@Root(name = "example")
public static class ListExample
{
@ElementList(name = "Shops", inline = true)
private List<Shop> shops;
// ...
}
用法
String input = ... // Or what source you have
Serializer ser = new Persister();
ListExample readExample = ser.read(ListExample.class, input);
关于java - 如何获取对象列表的点类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29302860/