Java XML JAXB Unmarshaller unmarshal(Class beanClass, InputStream is)

Here you can find the source of unmarshal(Class beanClass, InputStream is)

Description

unmarshal

License

Open Source License

Declaration

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

Method Source Code


//package com.java2s;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;
import java.io.InputStream;

import java.io.StringReader;

public class Main {
    private static JAXBContext jaxbContext;
    private static ThreadLocal<Unmarshaller> unmarshaller = new ThreadLocal<Unmarshaller>();

    @SuppressWarnings("unchecked")
    public static <T> T unmarshal(Class<T> beanClass, String xml) throws JAXBException {
        StringReader reader = new StringReader(xml);
        return (T) getUnmarshaller().unmarshal(reader);
    }//from   w  w w. ja v  a2  s .  co  m

    @SuppressWarnings("unchecked")
    public static <T> T unmarshal(Class<T> beanClass, InputStream is) throws JAXBException {
        return (T) getUnmarshaller().unmarshal(is);
    }

    private static Unmarshaller getUnmarshaller() throws JAXBException {
        Unmarshaller um = unmarshaller.get();
        if (um == null) {
            um = jaxbContext.createUnmarshaller();
            unmarshaller.set(um);
        }
        return um;
    }
}

Related

  1. getUnmarshaller()
  2. getUnmarshaller()
  3. getUnmarshaller()
  4. getUnmarshaller(Class jaxbClass)
  5. marshallUnmarshall(T inObj)
  6. unmarshal(Class c, Object o)
  7. unmarshal(Class clazz, Source source)
  8. unmarshal(Class clazz, String xml)
  9. unmarshal(Class clazz, String xmlInClassPath)