Here you can find the source of Xml2Object(String xmlString, Class> clazz)
public static Object Xml2Object(String xmlString, Class<?> clazz) throws JAXBException
//package com.java2s; //License from project: Open Source License import java.io.StringReader; import java.net.URL; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { public static Object Xml2Object(String xmlString, Class<?> clazz) throws JAXBException { if (xmlString == null || "".equals(xmlString.trim())) { return null; }/*w ww. j av a 2s .c om*/ Unmarshaller unmarshaller = createUnMarshallerByClazz(clazz); return unmarshaller.unmarshal(new StringReader(xmlString)); } public static Object Xml2Object(URL url, Class<?> clazz) throws JAXBException { if (url == null) { return null; } Unmarshaller unmarshaller = createUnMarshallerByClazz(clazz); return unmarshaller.unmarshal(url); } public static Unmarshaller createUnMarshallerByClazz(Class<?> clazz) throws JAXBException { JAXBContext jax = JAXBContext.newInstance(clazz); Unmarshaller unMar = jax.createUnmarshaller(); return unMar; } }