Here you can find the source of inputStreamToObject(InputStream xml, Class
@SuppressWarnings("unchecked") public static <T> T inputStreamToObject(InputStream xml, Class<T> clazz) throws JAXBException, IOException
//package com.java2s; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import java.io.IOException; import java.io.InputStream; public class Main { @SuppressWarnings("unchecked") public static <T> T inputStreamToObject(InputStream xml, Class<T> clazz) throws JAXBException, IOException { JAXBContext jaxbContext = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); try {//from www. j av a2 s.com return (T) unmarshaller.unmarshal(xml); } finally { xml.close(); } } }