public void serialize(String fileName) { try { JAXBContext jc = JAXBContext.newInstance(this.getClass().getPackage().getName()); Marshaller m = jc.createMarshaller(); m.marshal(this, new FileOutputStream(fileName)); } catch (Exception e) { e.printStackTrace(); } }
public static Configuration deserialize(String fileName) { try { JAXBContext jc = JAXBContext.newInstance((new Configuration()).getClass().getPackage().getName()); Unmarshaller um = jc.createUnmarshaller(); return (Configuration) um.unmarshal(new File(fileName)); } catch (Exception e) { e.printStackTrace(); return new Configuration(); } }