Here you can find the source of fromXml(String responseBody, Class
public static <T> T fromXml(String responseBody, Class<T> c) throws JAXBException, XMLStreamException
//package com.java2s; //License from project: Open Source License import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import java.io.ByteArrayInputStream; public class Main { private static XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); public static <T> T fromXml(String responseBody, Class<T> c) throws JAXBException, XMLStreamException { ByteArrayInputStream inputStream = new ByteArrayInputStream(responseBody.getBytes()); JAXBContext jaxbContext = JAXBContext.newInstance(c); XMLStreamReader xsr = xmlInputFactory.createXMLStreamReader(inputStream); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); return (T) jaxbUnmarshaller.unmarshal(xsr); }// w w w . j a v a2 s .co m }