Java tutorial
//package com.java2s; import java.io.InputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { public static <A> A unmarshal(Class<A> clazz, InputStream in) throws JAXBException { return clazz.cast(JAXBElement.class.cast(getUnmarshaller(clazz).unmarshal(in)).getValue()); } private static Unmarshaller getUnmarshaller(Class<?> clazz) throws JAXBException { return getContext(clazz).createUnmarshaller(); } private static JAXBContext getContext(Class<?> clazz) throws JAXBException { return JAXBContext.newInstance(clazz.getPackage().getName(), clazz.getClassLoader()); } }