Java XML JAXB String to Object fromXml(Class tClass, InputStream inputStream)

Here you can find the source of fromXml(Class tClass, InputStream inputStream)

Description

from Xml

License

Open Source License

Declaration

public static <T> T fromXml(Class<T> tClass, InputStream inputStream) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;

import java.io.InputStream;

public class Main {
    public static <T> T fromXml(Class<T> tClass, InputStream inputStream) {
        JAXBContext jaxbContext = null;
        try {// ww w. j  a v  a2 s .  co m
            jaxbContext = JAXBContext.newInstance(tClass);

            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            return (T) jaxbUnmarshaller.unmarshal(inputStream);
        } catch (JAXBException e) {
            e.printStackTrace();//TODO:log
            return null;
        }
    }
}

Related

  1. fromFile(Class jaxbClass, String fileName)
  2. fromStream(Class jaxbClass, InputStream is)
  3. fromStringToObject(String xmlString, Class xmlObjClass)
  4. fromXml(@SuppressWarnings("rawtypes") Class clazz, String stringXml)
  5. fromXML(Class clazz, InputStream is)
  6. fromXml(File xmlPath, Class type)
  7. fromXML(final byte[] data, final Class type)
  8. fromXml(final Reader reader, final Class dtoClass)
  9. fromXml(InputStream input, Class clazz)