Java XML JAXB Unmarshaller unmarshal(InputStream inputStream, Class entityClass)

Here you can find the source of unmarshal(InputStream inputStream, Class entityClass)

Description

Unmarshal XML data from the specified file and return the resulting object.

License

Open Source License

Parameter

Parameter Description
xml a parameter

Exception

Parameter Description
JAXBException an exception

Declaration

@SuppressWarnings("unchecked")
public static <T> T unmarshal(InputStream inputStream, Class<T> entityClass) throws JAXBException 

Method Source Code

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

Related

  1. unmarshal(final String xml, Class clazz, InputStream inputSchema)
  2. unmarshal(final String xml, final Class clazz)
  3. unmarshal(InputSource inputSource, Class clazz)
  4. unmarshal(InputStream content, Class expectedType)
  5. unmarshal(InputStream in, Class... boundClasses)
  6. unmarshal(InputStream inputStream, Class type)
  7. unmarshal(InputStream is, Class clazz)
  8. unmarshal(InputStream stream, Class clazz)
  9. unmarshal(JAXBContext context, Class clazz, String source)