List of utility methods to do XML JAXB Object to XML
String | asXml(T object) as Xml try { JAXBContext jaxbContext = null; jaxbContext = JAXBContext.newInstance(object.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); StringWriter writer = new StringWriter(); marshaller.marshal(object, writer); return writer.toString(); } catch (JAXBException e) { ... |
String | convertObjectToXML(Object object) convert Object To XML StringWriter sw = new StringWriter(); String xmlString = null; try { JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass()); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.marshal(object, sw); xmlString = sw.toString(); } catch (JAXBException e) { ... |
String | convertObjectToXml(Object object) convert Object To Xml return convertObjectToXml(object, "UTF-8"); |
String | convertToString(Object obj) convert To String try { JAXBContext context = JAXBContext.newInstance(obj.getClass()); StringWriter writer = new StringWriter(); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(obj, writer); return writer.toString(); } catch (JAXBException e) { ... |
String | convertToXml(Object obj) convert To Xml return convertToXml(obj, "UTF-8"); |
String | convertToXml(Object obj) convert To Xml return convertToXml(obj, "UTF-8"); |
String | convertToXml(Object obj, String encoding) convert To Xml String result = null; try { JAXBContext context = JAXBContext.newInstance(obj.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding); StringWriter writer = new StringWriter(); marshaller.marshal(obj, writer); result = writer.toString(); ... |
String | createXML(Object o) create XML JAXBContext jaxbContext = JAXBContext.newInstance(o.getClass()); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter result = new StringWriter(); jaxbMarshaller.marshal(o, result); String xml = result.toString(); return xml; |
List | getObjects(List Get the list of T from list of JAXBElement List<T> list = new ArrayList<T>(); for (JAXBElement<? extends T> objEl : objEls) { list.add(objEl.getValue()); return list; |
List | getObjects(List get Objects final List list = new ArrayList(); for (final JAXBElement objEl : objEls) { list.add(objEl.getValue()); return list; |