/** * Xml和对象转换工具 * * @author ljz * */ public class XmlUtils { /** * 对象转换为xml字符串 * * @param obj * @return */ public static String toXml(Object obj){ XStream xstream = new XStream(); return xstream.toXML(obj); } /** * xml转换为对象 * * @param xml * @param type * @return */ public static <T> T toObject(String xml, Class<T> type){ XStream xstream = new XStream(); xstream.processAnnotations(type); xstream.ignoreUnknownElements(); Object obj = xstream.fromXML(xml); return type.cast(obj); } }
Xml与实体类转换工具类
最新推荐文章于 2024-02-24 22:55:31 发布