标签:ar io sp java on 2014 bs as new
package com.wanhua.util;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
/**
* 利用XStream实现实体类与xml的转换
*
* @author w_xfpenga
*
* 2014-11-27
*/
public class XStream2Text {
static XStream xStream = new XStream(new DomDriver());
/**
* 将javaBean对象转成xml
*
* @param obj
* @return
*/
public static String Object2Xml(Object obj) {
xStream.autodetectAnnotations(true);
String xml = xStream.toXML(obj);
return xml;
}
/**
* 将xml转成javaBean对象
*
* @param xml
* @return
*/
public static Object xml2Object(String xml) {
xStream.autodetectAnnotations(true);
Object obj = xStream.fromXML(xml);
return obj;
}
}
标签:ar io sp java on 2014 bs as new
原文地址:http://www.cnblogs.com/xunfang123/p/4171310.html