List of utility methods to do XML JAXB Object to XML
String | getXmlString(JAXBElement versioningInfo, Boolean formatXml, Schema schema) get Xml String String packageName = versioningInfo.getValue().getClass().getPackage().getName(); JAXBContext context = JAXBContext.newInstance(packageName); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formatXml); if (schema != null) { marshaller.setSchema(schema); ByteArrayOutputStream oStream = new ByteArrayOutputStream(); ... |
String | getXMLString(Object person, Class> clazz) get XML String StringWriter sw = new StringWriter(); JAXBContext context = JAXBContext.newInstance(clazz); context.createMarshaller().marshal(person, sw); String output = sw.toString(); System.out.println(output); return output; |
String | getXmlString(T jaxbObject) get Xml String StringWriter sw = new StringWriter(); JAXBContext context = JAXBContext.newInstance(jaxbObject.getClass()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(jaxbObject, sw); return sw.toString(); |
String | Object2Xml(Object object) Object Xml Marshaller mar = createMarshallerByClazz(object.getClass()); StringWriter strWriter = new StringWriter(); mar.marshal(object, strWriter); return strWriter.toString(); |
String | objectToXML(Class> cls, Object entity) Return the xml translation of an object try { Marshaller m = JAXBContext.newInstance(cls).createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); StringWriter sw = new StringWriter(); m.marshal(entity, sw); return sw.toString(); } catch (Exception e) { ... |
String | ObjectToXml(Object object) Transforms an annotated Object to a XML string using javax.xml.bind.Marshaller JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); StringWriter sw = new StringWriter(); marshaller.marshal(object, sw); return sw.toString(); |
String | objectToXml(Object source, Class... type) object To Xml String result; StringWriter sw = new StringWriter(); try { JAXBContext jaxbContext = JAXBContext.newInstance(type); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(source, sw); result = sw.toString(); ... |
String | toString(E e) to String String charsetName = "utf-8"; ByteArrayOutputStream os = new ByteArrayOutputStream(); print(e, os, e.getClass()); try { return os.toString(charsetName); } catch (UnsupportedEncodingException e1) { throw new IllegalArgumentException(charsetName + " is not supported"); |
String | toString(Object o, Class clazz) toString marshals given Jaxb object to a string (useful for debug) StringWriter sw = new StringWriter(); try { JAXBContext jc = JAXBContext.newInstance(clazz); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(o, sw); } catch (Exception e) { e.printStackTrace(); ... |
String | toXml(Class className, Object object) to Xml String strXml = ""; StringWriter writer = null; try { writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(className); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(object, writer); ... |