Here you can find the source of parse(final Class
public static <T> T parse(final Class<T> clazz, final InputStream inputStream)
//package com.java2s; //License from project: LGPL import javax.xml.bind.*; import java.io.InputStream; public class Main { public static <T> T parse(final Class<T> clazz, final InputStream inputStream) { try {//from w ww . j a v a 2 s .co m final JAXBContext jaxbContext = JAXBContext.newInstance(clazz); final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); final Object deserialized = jaxbUnmarshaller.unmarshal(inputStream); if (clazz.isAssignableFrom(deserialized.getClass())) { return clazz.cast(deserialized); } else { final JAXBElement<T> jaxbElement = (JAXBElement<T>) deserialized; return jaxbElement.getValue(); } } catch (final JAXBException e) { throw new RuntimeException(e); } } }