Xstream:在结果xml中摆脱Collection实现

时间:2012-07-12 09:10:04

标签: java xml xml-serialization xstream

使用Xstream摆脱这些东西的最简单方法是什么:

<myRows class="java.util.Collections$UnmodifiableRandomAccessList" ...

最好我想要删除所有List实现,并在读取时将它们反序列化为plain ArrayList。我已经为我自己的类做了基本的别名,并且有效,例如

"foo.bar.MyClass" -> "my-class"

1 个答案:

答案 0 :(得分:0)

您可以实现Converter接口来更改转换细节:`public class MyConverter实现Converter {

public boolean canConvert(Class type) {
    // TODO Auto-generated method stub
    return false;
}

public void marshal(Object source, HierarchicalStreamWriter writer,
        MarshallingContext context) {
    // TODO Auto-generated method stub

}

public Object unmarshal(HierarchicalStreamReader reader,
        UnmarshallingContext context) {
    // TODO Auto-generated method stub
    return null;
}

}

并注册您的转换器:

xStream.registerConverter(new MyConverter());

`