List of utility methods to do XML JAXB Object to XML
byte[] | toXML(final Object obj, final boolean prettyPrint) Converts object to XML and returns the byte array of the XML text created. return toXML(obj, prettyPrint, null);
|
String | toXml(final T dto) to Xml final CharArrayWriter caw = new CharArrayWriter(); toXml(dto, caw); return caw.toString(); |
String | toXML(Object o) to XML StringWriter writer = new StringWriter(); javax.xml.bind.JAXB.marshal(o, writer); return writer.toString(); |
void | toXML(Object o, OutputStream os) to XML JAXBContext context = JAXBContext.newInstance(o.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.marshal(o, os);
|
void | toXml(Object o, OutputStream output) to Xml try { JAXBContext context = JAXBContext.newInstance(o.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, CHARSET); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(o, new OutputStreamWriter(output, CHARSET)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); ... |
String | toXml(Object obj) to Xml StringWriter sw = new StringWriter(); JAXBContext context = JAXBContext.newInstance(obj.getClass()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(obj, sw); return sw.toString(); |
String | toXml(Object object) to Xml final StringWriter out = new StringWriter(); JAXBContext context = null; try { context = JAXBContext.newInstance(object.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(object, new StreamResult(out)); } catch (PropertyException e) { ... |
String | toXML(Object thing) to XML StringWriter sw = new StringWriter(); try { JAXBContext jaxbContext = JAXBContext.newInstance(thing.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(thing, sw); return sw.toString(); ... |
String | toXml(T element) to Xml try { Marshaller marshaller = JAXBContext.newInstance(element.getClass()).createMarshaller(); StringWriter writer = new StringWriter(); marshaller.marshal(element, writer); return writer.toString(); } catch (JAXBException e) { throw new IllegalStateException(e); |
String | toXml(T object) to Xml JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter writer = new StringWriter(); marshaller.marshal(object, writer); return writer.toString(); |