Here you can find the source of unmarshal(InputStream inputStream, Class
Parameter | Description |
---|---|
xml | a parameter |
Parameter | Description |
---|---|
JAXBException | an exception |
@SuppressWarnings("unchecked") public static <T> T unmarshal(InputStream inputStream, Class<T> entityClass) throws JAXBException
//package com.java2s; import java.io.InputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { /**//from www . ja v a2 s . c o m * Unmarshal XML data from the specified file and return the resulting object. * * @param xml * @return * @throws JAXBException */ @SuppressWarnings("unchecked") public static <T> T unmarshal(InputStream inputStream, Class<T> entityClass) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(entityClass); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); T document = (T) jaxbUnmarshaller.unmarshal(inputStream); return document; } }