Java tutorial
//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); } }