我想用SimpleFramework xml序列化一个Object对象。 我使用普通类成功但不使用对象列表。
我没有找到使用List of object执行此操作的良好语法。
List< Shop > shop = new Persister().read(List<Shop>.class, data);
List< Shop >.class
无法正常工作
由于
答案 0 :(得分:1)
不可能直接这样做;请改用@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);