import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
/**
* Xstream工具类。
*/
public class XstreamUtil {
private static XStream xstream = null;
private static String ENCODING = "UTF-8";
/**
* 获取xstream对象。
*
* @return Xstream对象
*/
public static XStream getXstream() {
if (xstream == null) {
xstream = new XStream(new DomDriver(ENCODING));
}
xstream.autodetectAnnotations(true);
return xstream;
}
}
用法:
XStream xStream = XstreamUtil.getXstream();
xStream.processAnnotations(Object.class); //启动注解
@XStreamImplicit //忽略某个属性
Java Xstream基本用法
最新推荐文章于 2024-05-18 09:35:25 发布