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;
}
}
时间: 2024-10-12 10:19:17