利用XStream实现实体类与xml的转换
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;
}
}
posted on 2014-12-18 11:28 w_xunfangA 阅读(406) 评论(0) 编辑 收藏 举报