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);