Java XML JAXB Unserialize inputStreamToObject(InputStream xml, Class clazz)

Here you can find the source of inputStreamToObject(InputStream xml, Class clazz)

Description

input Stream To Object

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <T> T inputStreamToObject(InputStream xml, Class<T> clazz) throws JAXBException, IOException 

Method Source Code


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

Related

  1. inputStreamToObject(String xml, Class clazz, Class[] classes)
  2. load(Class clazz, InputStream is)
  3. load(Class clazz, InputStream is)
  4. load(File f, Class... args)