Java XML JAXB Unserialize readJaxbObject(InputStream inputStream, Class jaxbModelClass)

Here you can find the source of readJaxbObject(InputStream inputStream, Class jaxbModelClass)

Description

read Jaxb Object

License

Open Source License

Parameter

Parameter Description
inputStream a parameter
jaxbModelClass a parameter

Exception

Parameter Description
JAXBException an exception

Declaration

public static <T> T readJaxbObject(InputStream inputStream, Class<T> jaxbModelClass) throws JAXBException 

Method Source Code


//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();
    }
}

Related

  1. read(Class cl, InputStream is)
  2. read(File file, Class typeParameterClass)
  3. readComplexProperty(String name, List objects, String methodName)
  4. readExternal(InputStream inputStream, Class clazz)
  5. readJAXB(Class clazz, InputStream is)
  6. readObject(Class clazz, File file)
  7. readObjectFromInputStream(final InputStream inputStream, final Class expectedType)
  8. readObjectFromXml(Class jaxbBindClass, String xmlFileName)
  9. readXmlFileToObj(String path, String packageName)

  10. HOME | Copyright © www.java2s.com 2016