Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. public Group unmarshall() {
  2. try(InputStream inputStream = new FileInputStream("resources/office_list.xml")) {
  3. JAXBContext context = JAXBContext.newInstance(Group.class);
  4. Marshaller marshaller = context.createMarshaller();
  5. marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
  6.  
  7. //write XML to an array of bytes
  8. //ByteArrayOutputStream baos = new ByteArrayOutputStream();
  9. //marshaller.marshal(createJavaObjectExample1(), baos);
  10.  
  11. //read XML from array of bytes
  12. //InputStream bais = new ByteArrayInputStream(baos.toByteArray());
  13.  
  14. Unmarshaller unmarshaller = context.createUnmarshaller();
  15. Object o = unmarshaller.unmarshal(inputStream);
  16. group = (Group) o;
  17. //System.out.println(group.getName());
  18.  
  19. return group;
  20. } catch (JAXBException exception) {
  21. Logger.getLogger(Application.class.getName()).
  22. log(Level.SEVERE, "saveMarshall threw JAXBException", exception);
  23. } catch (IOException e) {
  24. e.printStackTrace();
  25. }
  26. return null;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement