我想使用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 */ }

    // ...
}


ListExample

这只是列表的包装。

@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/

10-11 02:43
查看更多