如何获取对象列表的点 class?

How to get dot class of list of Objects?

我想用 SimpleFramework 序列化对象列表 xml。 我用普通 class 成功了,但用对象列表没有成功。

我找不到使用对象列表来执行此操作的良好语法。

List< Shop > shop = new Persister().read(List<Shop>.class, data);

List< Shop >.class 无效

谢谢

无法直接执行此操作;请改用 @ElementList

这是一个例子:

购物class

@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);