Skip to content

Instantly share code, notes, and snippets.

@james-prickett
Created June 3, 2014 22:15
Show Gist options
  • Select an option

  • Save james-prickett/01aea289fd5c7c927f33 to your computer and use it in GitHub Desktop.

Select an option

Save james-prickett/01aea289fd5c7c927f33 to your computer and use it in GitHub Desktop.
JAXB Example
public static void main(String[] args) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance("com.prickettfamily.java.jaxb");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Person person = (Person)unmarshaller.unmarshal(new File("/home/james/person.xml"));
assert person.getName().equals("John Doe");
assert person.getPhone().equals("555-5555");
assert person.getAddress().getStreet().equals("5 Somewhere Lane");
} catch (JAXBException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment