我正在使用 spring 运行一个 webapp,并且我使用 xstream 作为我的序列化工具。我已经定义了一个包含自定义转换器的 marsheller,但是在读取 xml 时,我注册的转换器似乎被忽略了,因为 xstream 无法正确解析某些字段。
这是编组器的init函数:
public void init() {
XStream xstream = new XStream() {
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new MapperWrapper(next) {
public boolean shouldSerializeMember(Class definedIn, String fieldName) {
return definedIn != Object.class ? super.shouldSerializeMember(definedIn, fieldName) : false;
}
};
}
};
xstream.setMode(XStream.NO_REFERENCES);
xstream.addDefaultImplementation(ArrayList.class, PersistentList.class);
xstream.addDefaultImplementation(ArrayList.class, PersistentBag.class);
xstream.addDefaultImplementation(HashMap.class, PersistentMap.class);
xstream.addDefaultImplementation(java.util.HashSet.class, PersistentSet.class);
xstream.alias("Array", PersistentBag.class);
xstream.alias("list", PersistentBag.class);
Mapper mapper = xstream.getMapper();
xstream.registerConverter(new HibernateCollectionConverter(mapper));
xstream.registerConverter(new HibernateMapConverter(mapper));
xstream.registerConverter(new DateConverter());
xstream.registerConverter(new TimeStampCustomConverter());
xstream.registerConverter(new LongConverter());
xstream.registerConverter(new IntConverter());
xstream.registerConverter(new DoubleConverter());
}
我错过了什么?