Java XML JAXB Unmarshaller unmarshall(Class cls, Element domRequest)

Here you can find the source of unmarshall(Class cls, Element domRequest)

Description

Unmarshall from DOM Element to a generic JAXBElement

License

LGPL

Parameter

Parameter Description
T a parameter
cls a parameter
domRequest a parameter

Declaration

private static <T> T unmarshall(Class<T> cls, Element domRequest) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;

import org.w3c.dom.Element;

public class Main {
    /**//w  ww.  j av  a 2 s  . c  o m
     * Unmarshall from DOM Element to a generic JAXBElement
     * 
     * @param <T>
     * @param cls
     * @param domRequest
     * @return
     */
    private static <T> T unmarshall(Class<T> cls, Element domRequest) {

        try {
            JAXBContext jc = JAXBContext.newInstance(cls);
            Unmarshaller unmarshaller = jc.createUnmarshaller();

            JAXBElement<T> jaxbObject = unmarshaller.unmarshal(domRequest,
                    cls);

            return jaxbObject.getValue();
        } catch (JAXBException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. unmarshalFromXml(Class clazz, String xml)
  2. unmarshalFromXml(final String xml, Class destinationClass)
  3. unmarshalInstance(final String data, final Class expectedType)
  4. unmarshall(Class clazz, String string)
  5. unmarshall(Class c, Object o)
  6. unmarshall(InputStream is, Class clz)
  7. unmarshall(InputStream toUnmarshall, Class clazz)
  8. unmarshall(JAXBContext c, Element e)
  9. unmarshall(String cntxtPkg, InputStream in)