Java Utililty Methods XML JAXB Unmarshaller

List of utility methods to do XML JAXB Unmarshaller

Description

The list of methods to do XML JAXB Unmarshaller are organized into topic(s).

Method

Tunmarshal(Class clz, File file)
unmarshal
Unmarshaller u = _jaxbContexts.get(clz).createUnmarshaller();
return clz.cast(u.unmarshal(file));
Objectunmarshal(File f)
Unmarshals a file.
return unmar.unmarshal(f);
Objectunmarshal(final Class clazz, String json)
unmarshal
Gson gson = new Gson();
return gson.fromJson(json, clazz);
Tunmarshal(final String xml, Class clazz, InputStream inputSchema)
Unmarshalls the XML string given the JaxB class.
try {
    JAXBContext ctxt = JAXBContext.newInstance(clazz);
    Unmarshaller u = ctxt.createUnmarshaller();
    if (inputSchema != null) {
        if (inputSchema != null) {
            SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = sf.newSchema(new StreamSource(inputSchema));
            u.setSchema(schema);
...
Tunmarshal(final String xml, final Class clazz)
JAXBContext.newInstance(..) is a slow operation.
return (T) unmarshal(JAXBContext.newInstance(clazz), xml);
Objectunmarshal(InputSource inputSource, Class clazz)
Unmarshal.
JAXBContext jc = JAXBContext.newInstance(clazz);
Unmarshaller u = jc.createUnmarshaller();
ValidationEventCollector vec = new ValidationEventCollector();
u.setEventHandler(vec);
Object o1 = u.unmarshal(inputSource);
return o1;
Tunmarshal(InputStream content, Class expectedType)

Unmarshal XML data from InputStream by expectedType and return the resulting content tree.

return unmarshal(new StreamSource(content), expectedType);
Tunmarshal(InputStream in, Class... boundClasses)
unmarshal
try {
    Unmarshaller u = JAXBContext.newInstance(boundClasses).createUnmarshaller();
    return (T) u.unmarshal(in);
} catch (Exception ex) {
return null;
Tunmarshal(InputStream inputStream, Class entityClass)
Unmarshal XML data from the specified file and return the resulting object.
JAXBContext jaxbContext = JAXBContext.newInstance(entityClass);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
T document = (T) jaxbUnmarshaller.unmarshal(inputStream);
return document;
Tunmarshal(InputStream inputStream, Class type)
Attempts to unmarshal an XML document from an InputStream.
JAXBContext jaxbContext = JAXBContext.newInstance(type.getPackage().getName());
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
@SuppressWarnings("unchecked")
JAXBElement<T> jaxbElement = (JAXBElement<T>) unmarshaller.unmarshal(inputStream);
return jaxbElement.getValue();