How to assign your xml file to jaxb object

Wednesday of September 05, 2012

This method converts your xml file contained in a XMLStreamReader to a jaxb object.

/**
 * @param XMLStreamReader reader
 * @param String package name where the jaxb java files are stored
 * @throws JAXBException is throw if any errors occured
 */

public static Object xmlToJaxb(XMLStreamReader reader, String jaxbContextPackage)
    throws JAXBException {
  HashMap jaxbMap = new HashMap();
  JAXBContext jaxbContext;
  jaxbContext = JAXBContext.newInstance(jaxbContextPackage);
  jaxbMap.put(jaxbContextPackage, jaxbContext);
  Unmarshaller um = jaxbContext.createUnmarshaller();
  return um.unmarshal(reader);
}