XSTREAM短期动态别名 [英] XStream short dynamic aliases
问题描述
我想为类短名称,现在我可以用别名做
I want to have short names for classes, now i can do it with aliases
XStream x = new XStream();
x.alias("dic", Dic.class);
但我必须手动定义别名每一个类,有没有什么办法来配置的XStream自动办呢?
but i have to define alias manually for every class, is there any way to configure xstream to do it automatically?
推荐答案
在内部,XStream的使用它映射
接口来处理的类和字段映射到其对应的名字在的XML。还有大量的此接口的实现。在 XStream的
类本身可以采取映射
在其构造。您可能要检查出类的源$ C $ C看到它使用了映射实现默认,然后写自己的实现自动执行的走样你。 ClassAliasingMapper
看起来很有用,例如
Internally, XStream uses its Mapper
interface to handle the mapping of classes and fields to their corresponding names in the XML. There are a large number of implementations of this interface. The XStream
class itself can take a Mapper
in its constructor. You might want to check out the source code of that class to see which Mapper implementation it uses by default, and then write your own implementation that automatically does your aliasing for you. ClassAliasingMapper
looks useful, for example.
这篇关于XSTREAM短期动态别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!