xml 报文转对象方法

来源:互联网 发布:c语言 string.h库函数 编辑:程序博客网 时间:2024/06/06 12:05
import java.io.StringReader;import javax.xml.bind.JAXBContext;import javax.xml.bind.JAXBException;import javax.xml.bind.Unmarshaller;public class XmlTransTools {public static<T> T Xml2JBean(String sourceXml,Class<T> target) throws JAXBException {JAXBContext context = JAXBContext.newInstance(target); Unmarshaller unmarshaller = context.createUnmarshaller();  @SuppressWarnings("unchecked")T result = (T) unmarshaller.unmarshal(new StringReader(sourceXml));return result;}}
WeixinResponse weixinResponse = XmlTransTools.Xml2JBean(xmlParam, WeixinResponse.class);


0 0