Here you can find the source of readJaxbObject(InputStream inputStream, Class
Parameter | Description |
---|---|
inputStream | a parameter |
jaxbModelClass | a parameter |
Parameter | Description |
---|---|
JAXBException | an exception |
public static <T> T readJaxbObject(InputStream inputStream, Class<T> jaxbModelClass) throws JAXBException
//package com.java2s; //License from project: Open Source License import java.io.InputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.bind.helpers.DefaultValidationEventHandler; import javax.xml.transform.stream.StreamSource; public class Main { /**/* w w w.j a v a2 s . com*/ * * @param inputStream * @param jaxbModelClass * @return * @throws JAXBException */ public static <T> T readJaxbObject(InputStream inputStream, Class<T> jaxbModelClass) throws JAXBException { JAXBContext context = JAXBContext.newInstance(jaxbModelClass.getPackage().getName()); Unmarshaller unmarshaller = context.createUnmarshaller(); unmarshaller.setEventHandler(new DefaultValidationEventHandler()); return unmarshaller.unmarshal(new StreamSource(inputStream), jaxbModelClass).getValue(); } }