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

Tunmarshall(String file, Class desiredClass, Class context)
unmarshall
JAXBContext ctx = JAXBContext.newInstance(context);
Unmarshaller unMarshaller = ctx.createUnmarshaller();
JAXBElement<T> object = (JAXBElement<T>) unMarshaller.unmarshal(new File(file));
return object.getValue();
Objectunmarshall(String xml, Class... classesToBeBound)
unmarshall
JAXBContext context = JAXBContext.newInstance(classesToBeBound);
Unmarshaller unmarshaller = context.createUnmarshaller();
StringReader reader = new StringReader(xml);
return unmarshaller.unmarshal(reader);
Tunmarshall(String xml, Class clazz)
unmarshall
JAXBContext ctx = JAXBContext.newInstance(clazz);
Unmarshaller m = ctx.createUnmarshaller();
StringReader reader = new StringReader(HEADER + xml);
return (T) m.unmarshal(reader);
Objectunmarshall(String xml, URL schemaURL, Class... classesToBeBound)
unmarshall
JAXBContext context = JAXBContext.newInstance(classesToBeBound);
Unmarshaller unmarshaller = context.createUnmarshaller();
if (schemaURL != null) {
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(schemaURL);
    unmarshaller.setSchema(schema);
StringReader reader = new StringReader(xml);
...
Tunmarshaller(Class entityType, InputStream in)
unmarshaller
Unmarshaller unmarshaller = createUnmarshaller(entityType);
return (T) unmarshaller.unmarshal(in);
Tunmarshaller(String xml, Class T)
unmarshaller
JAXBContext jc;
Unmarshaller unmarshaller;
Object o = null;
try {
    jc = JAXBContext.newInstance(T);
    unmarshaller = jc.createUnmarshaller();
    o = unmarshaller.unmarshal(new StreamSource(new StringReader(xml)));
} catch (JAXBException e) {
...
BoundTypeunmarshallJAXBElement(JAXBElement v)
unmarshall JAXB Element
if (v == null) {
    return null;
} else {
    return v.getValue();
ObjectunMarshallRequest(String xmlString)
un Marshall Request
Object request = null;
try {
    Unmarshaller um = getRequestContext().createUnmarshaller();
    request = um.unmarshal(new ByteArrayInputStream(xmlString.getBytes()));
} catch (JAXBException je) {
    je.printStackTrace();
return request;
...
TunmarshallString(String str, Class c)
unmarshall String
initUnmarshaller(c);
ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes());
return (T) um.unmarshal(bis);
OBJECT_TYPEunmarshallXml(final String string, final Class type)
unmarshall Xml
return unmarschall(string, type, null);