Here you can find the source of convertXMLToObject(byte[] data, Class
public static <T> T convertXMLToObject(byte[] data, Class<T> clazz) throws JAXBException
//package com.java2s; //License from project: Apache License import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import java.io.ByteArrayInputStream; public class Main { public static <T> T convertXMLToObject(byte[] data, Class<T> clazz) throws JAXBException { javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(clazz.getPackage().getName()); Unmarshaller um = jaxbCtx.createUnmarshaller(); JAXBElement<T> element = (JAXBElement<T>) um.unmarshal(new ByteArrayInputStream(data)); return element.getValue(); }/*from ww w.j a v a 2 s .co m*/ }