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

TunmarshallXMLtoObject(final byte[] xmlObject, final Class objectClass, final URL schemaURL)
unmarshall XM Lto Object
if (xmlObject == null) {
    return null;
if (schemaURL == null) {
    throw new IllegalArgumentException("schemaURL is null");
final SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final Schema schema = sf.newSchema(schemaURL);
...
TunmarshalObject(final InputStream input, final Class clazz)
unmarshal Object
Unmarshaller unmarshaller = JAXBContext.newInstance(clazz).createUnmarshaller();
return (T) unmarshaller.unmarshal(input);
PackageunmarshalPackage(InputStream pkgStream)
unmarshal Package
Source source = new StreamSource(pkgStream);
JAXBContext jc = JAXBContext.newInstance(ORG_ZEND_SDKLIB_DESCRIPTOR_PKG);
Unmarshaller u = jc.createUnmarshaller();
Package pkg = (Package) u.unmarshal(source);
return pkg;
TunmarshalXML(String xmlString, Class classType)
Un-marshall given string to given class type
T t = null;
if (xmlString != null) {
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xmlString.toString().getBytes());
    JAXBContext jaxbContext = JAXBContext.newInstance(classType);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    t = (T) jaxbUnmarshaller.unmarshal(byteArrayInputStream);
return t;
...
TunmarshalXmlToObject(String xmlFilePath, Class clazz)
Consumes the contents of the specified XML file, and creates a new Java object of the specified class that will contain the consumed contents.
if (clazz == null) {
    return null;
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
@SuppressWarnings("unchecked")
T result = (T) jaxbUnmarshaller.unmarshal(new java.io.FileInputStream(xmlFilePath));
return result;
...