Skip to content

Instantly share code, notes, and snippets.

@lanwen
Last active December 26, 2015 02:59
Show Gist options
  • Save lanwen/7082123 to your computer and use it in GitHub Desktop.
Save lanwen/7082123 to your computer and use it in GitHub Desktop.
Way to unmarshall jaxb-objects from xml
public static <T> T unmarshal(Class<T> clazz, String xml) throws JAXBException {
JAXBContext jc = JAXBContext.newInstance(clazz);
Unmarshaller u = jc.createUnmarshaller();
JAXBElement<T> root = u.unmarshal(new StreamSource(IOUtils.toInputStream(xml)), clazz);
return root.getValue();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment