fun serializeFile(path: String?, o: Any) { try { val context: JAXBContext = JAXBContext.newInstance(o.javaClass) val m: Marshaller = context.createMarshaller() m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE) val stream = FileOutputStream(path) m.marshal(o, stream) } catch (e: JAXBException) { e.printStackTrace() } catch (e: FileNotFoundException) { e.printStackTrace() } }
Serializes an object and saves it to a file , located at given path .