List of utility methods to do XML JAXB Serialize
void | save(Class confClass, Object confObj, File xmlFile) save JAXBContext context = JAXBContext.newInstance(confClass);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(confObj, new FileWriter(xmlFile));
|
void | save(File file, T obj, Class>... clazz) save JAXBContext jc = JAXBContext.newInstance(clazz); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(obj, file); |
void | saveDataToFile(File file, T data) Saves the data in the file in xml format. assert file != null; assert data != null; if (!file.exists()) { throw new FileNotFoundException("File not found : " + file.getAbsolutePath()); JAXBContext context = JAXBContext.newInstance(data.getClass()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); ... |
String | saveModel(JAXBElement model, String packageName) save Model JAXBContext jc; try { jc = JAXBContext.newInstance(packageName); Marshaller m = jc.createMarshaller(); ByteArrayOutputStream o = new ByteArrayOutputStream(); m.marshal(model, o); return new String(o.toByteArray()); } catch (Exception e) { ... |
void | saveObject(Path path, T object) Saves the object to the file. if (path == null || object == null) { throw new RuntimeException("The path to file or object is null!"); try { JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass()); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(object, path.toFile()); ... |
void | saveObject(T object, Class save Object try { File file = new File(path.toURI()); JAXBContext jaxbContext = JAXBContext.newInstance(typeClass); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(object, file); } catch (JAXBException e) { e.printStackTrace(); ... |
void | saveToFile(String fileName, T obj) save object to xml file using outputStream, JAXNContext and marshaller FileOutputStream outputStream = null; try { outputStream = new FileOutputStream(fileName); } catch (FileNotFoundException e) { e.printStackTrace(); try { JAXBContext jaxbContext = JAXBContext.newInstance(obj.getClass()); ... |
void | saveXML(Object object, String fileNamePath, Boolean append) save XML Marshaller marshaller = createMarshaller(object); File file = createFile(fileNamePath); FileWriter fileWriter; try { fileWriter = new FileWriter(file, append); if (append) { fileWriter.append(System.getProperty("line.separator")); marshaller.marshal(object, fileWriter); } catch (IOException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); |
String | serialiseObject(Object obj, Class> objclass) serialise Object JAXBContext jaxbContext = getJAXBContext(objclass); Marshaller m = jaxbContext.createMarshaller(); StringWriter w = new StringWriter(); m.marshal(obj, w); String xmlString = w.toString(); return xmlString; |
String | serialize(final Object object) serialize OutputStream outputStream = new ByteArrayOutputStream(); ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(outputStream, object); return outputStream.toString(); |