作者:封鹏 | 来源:互联网 | 2023-06-07 15:22
注解+代码
com.thoughtworks.xstream
xstream
1.4.10
注解:
@XStreamAlias("a")
代码:
public T transferXMLToBean(Class clazz, String str) {
XStream xstream = new XStream();
xstream.processAnnotations(clazz);
xstream.autodetectAnnotations(true);
xstream.setupDefaultSecurity(xstream);
xstream.allowTypes(new Class[]{clazz});
//或// xstream.allowTypesByRegExp(new String[] {".*"});
xstream.setClassLoader(clazz.getClassLoader());//这行是重点
return (T)xstream.fromXML(str);
}