XStream short dynamic aliases

后端 未结 3 888
太阳男子
太阳男子 2021-01-06 04:47

I want to have short names for classes, now i can do it with aliases

XStream x = new XStream();
x.alias(\"dic\", Dic.class);

but i have to

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 05:29

    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.

提交回复
热议问题