Here you can find the source of unmarshal(Class
public static <T> T unmarshal(Class<T> clazz, Source source) throws JAXBException
//package com.java2s; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.transform.Source; public class Main { public static <T> T unmarshal(Class<T> clazz, Source source) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = jc.createUnmarshaller(); JAXBElement<T> jaxbElement = unmarshaller.unmarshal(source, clazz); T object = jaxbElement.getValue(); return object; }/*from w ww .j av a 2 s .co m*/ }