List of utility methods to do XML JAXB Marshaller
String | marshallJAXBObject(String namespace, Object o) Marshall a JAXB object and return the XML as a string. return marshallJAXBObject(namespace, o, true);
|
void | marshallMessage(Object message, Marshaller marshaller, DataOutputStream dos) marshall Message ByteArrayOutputStream baos = new ByteArrayOutputStream(); marshaller.marshal(message, baos); byte[] buff = baos.toByteArray(); dos.writeInt(buff.length); dos.write(buff); dos.flush(); |
String | marshallObjectAsString(Class marshall Object As String JAXBContext jaxbContext = JAXBContext.newInstance(clazz); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter writer = new StringWriter(); jaxbMarshaller.marshal(object, writer); return writer.toString(); |
byte[] | marshallObjectToXML(final Object jaxbModel, final URL schemaURL) marshall Object To XML if (jaxbModel == null) { return null; if (schemaURL == null) { throw new IllegalArgumentException("schemaURL is null"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); ... |
String | marshallToString(Object jaxbElement, Class marshall To String initMarshaller(c); ByteArrayOutputStream fos = new ByteArrayOutputStream(); m.marshal(jaxbElement, fos); fos.flush(); String res = fos.toString("UTF-8"); fos.close(); return res; |
void | marshallToXml(String zpackage, Writer writer, Object data) marshall To Xml JAXBContext jc; try { jc = JAXBContext.newInstance(zpackage); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(data, writer); } catch (JAXBException e) { throw new RuntimeException(e); ... |
String | marshallXml(final Object object) marshall Xml return marschall(object, null);
|
void | marshallXMLInConsole(Object obj) marshall XML In Console try { JAXBContext context = JAXBContext.newInstance(obj.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(obj, System.out); } catch (Exception e) { e.printStackTrace(); |
void | marshalObject(Object obj, File file) marshal Object try { JAXBContext jaxbContext = JAXBContext.newInstance("com.osafe.feeds.osafefeeds"); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(obj, file); } catch (JAXBException e) { e.printStackTrace(); |
void | marshalObjectToXml(Object object, String xmlFilePath) Creates a new XML file based on the contents and schema contained in the specified JAXB object. if (object == null) { return; JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass()); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); File xmlFile = new File(xmlFilePath); jaxbMarshaller.marshal(object, xmlFile); ... |