XSTREAM短期动态别名 [英] XStream short dynamic aliases

查看:168
本文介绍了XSTREAM短期动态别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为类短名称,现在我可以用别名做

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看到它使用了映射实现默认,然后写自己的实现自动执行的走样你。 ClassAlias​​ingMapper 看起来很有用,例如

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆