Here you can find the source of toObject(String xml, Class
public static <T> T toObject(String xml, Class<T> clazz) throws JAXBException
//package com.java2s; //License from project: Open Source License import java.io.StringReader; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.transform.stream.StreamSource; public class Main { public static <T> T toObject(String xml, Class<T> clazz) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(clazz); Unmarshaller um = jc.createUnmarshaller(); StringReader reader = new StringReader(xml); StreamSource source = new StreamSource(reader); JAXBElement<T> elem = um.unmarshal(source, clazz); return elem.getValue(); }/* www.j a va2 s. c om*/ }