List of utility methods to do XML JAXB Serialize
void | serialize(JAXBElement emp, Class serialize JAXBContext context = getContext(clazz); try { Marshaller m = context.createMarshaller(); if (debug) { m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(emp, System.out); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE); m.marshal(emp, out); } catch (JAXBException e) { throw new IllegalStateException(e); |
String | serialize(JAXBElement serialize Class<?> clazz = object.getValue().getClass(); JAXBContext context = JAXBContext.newInstance(clazz.getPackage().getName()); Marshaller marshaller = context.createMarshaller(); StringWriter sw = new StringWriter(); marshaller.marshal(object, sw); sw.close(); return sw.toString(); |
void | serialize(Object o, OutputStream os, Boolean format) serialize Marshaller m = CTX.createMarshaller();
m.setEventHandler(new DefaultValidationEventHandler());
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, format);
m.marshal(o, os);
|
void | serialize(Object o, OutputStream os, Boolean format) serialize String pkg = o.getClass().getPackage().getName(); JAXBContext jc = getCachedContext(pkg); Marshaller m = jc.createMarshaller(); m.setEventHandler(new DefaultValidationEventHandler()); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, format); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); m.marshal(o, os); |
String | serialize(Object obj) serialize try { JAXBContext jc = JAXBContext.newInstance(obj.getClass()); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter sw = new StringWriter(); m.marshal(obj, sw); return sw.toString(); ... |
byte[] | serialize(Object obj) serialize ByteArrayOutputStream bos = new ByteArrayOutputStream(); serialize(obj, bos); return bos.toByteArray(); |
void | serialize(Object object, Class serialize JAXBContext context = JAXBContext.newInstance(clazz);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(object, new File(filename));
|
void | serialize(T object, Class serialize serialize(object, resultStream); |
void | serialize(T object, Path path) serialize serialize(object, path.toFile()); |
void | serializeFile(String path, Object o) Serializes an object and saves it to a file, located at given path. try { JAXBContext context = JAXBContext.newInstance(o.getClass()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); FileOutputStream stream = new FileOutputStream(path); m.marshal(o, stream); } catch (JAXBException e) { e.printStackTrace(); ... |