liujie
21 小时以前 74f8b8074a2fb391b5363b4dca5f99bf31993430
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.supersavedriving.user.modular.system.util.bank.parmUtil;
 
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.naming.NoNameCoder;
import com.thoughtworks.xstream.io.xml.Xpp3DomDriver;
 
public class XstreamUtils {
    public static <T> T toBean(String xml, Class<T> clazz) {
        XStream stream = new XStream();
        stream.processAnnotations(clazz);
        stream.autodetectAnnotations(true);
        stream.setClassLoader(clazz.getClassLoader());
        return (T) stream.fromXML(xml);
    }
 
    public static String toXml(Object obj, Class clazz) {
        XStream stream = new XStream(new Xpp3DomDriver(new NoNameCoder()));
        stream.processAnnotations(clazz);
        stream.autodetectAnnotations(true);
        stream.setClassLoader(clazz.getClassLoader());
        return stream.toXML(obj);
    }
}