Skip to content

Instantly share code, notes, and snippets.

@jonashackt
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonashackt/f8580d18a5b3ae67840d to your computer and use it in GitHub Desktop.
Save jonashackt/f8580d18a5b3ae67840d to your computer and use it in GitHub Desktop.
Marhall an JAXBObject into org.w3c.dom.Document
public static Document marhallJaxbElement(Object jaxbElement) throws BusinessException {
Document jaxbDoc = null;
try {
Marshaller marshaller = setUpMarshaller(jaxbElement.getClass());
jaxbDoc = createNewDocument();
marshaller.marshal(jaxbElement, jaxbDoc);
} catch (Exception exception) {
throw new BusinessException("Problem beim marshallen des JAXBElements in ein Document: " + exception.getMessage());
}
return jaxbDoc;
}
private static Document createNewDocument() throws BusinessException {
return setUpDocumentBuilder().newDocument();
}
private static <T> Marshaller setUpMarshaller(Class<T> jaxbElementClass) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(jaxbElementClass);
return jaxbContext.createMarshaller();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment