本文整理汇总了Java中com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter类的典型用法代码示例。如果您正苦于以下问题:Java AbstractSingleValueConverter类的具体用法?Java AbstractSingleValueConverter怎么用?Java AbstractSingleValueConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractSingleValueConverter类属于com.thoughtworks.xstream.converters.basic包,在下文中一共展示了AbstractSingleValueConverter类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createXStream
import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected XStream createXStream() {
XStream xstream = null;
if (brokerContext != null) {
Map<String, XStream> beans = brokerContext.getBeansOfType(XStream.class);
for (XStream bean : beans.values()) {
if (bean != null) {
xstream = bean;
break;
}
}
}
if (xstream == null) {
xstream = new XStream();
}
// For any object whose elements contains an UTF8Buffer instance instead of a String
// type we map it to String both in and out such that we don't marshal UTF8Buffers out
xstream.registerConverter(new AbstractSingleValueConverter() {
@Override
public Object fromString(String str) {
return str;
}
@SuppressWarnings("rawtypes")
@Override
public boolean canConvert(Class type) {
return type.equals(UTF8Buffer.class);
}
});
xstream.alias("string", UTF8Buffer.class);
return xstream;
}