List of utility methods to do XML JAXB Marshaller
String | marshall(Object o) marshall return marshall(o, o.getClass());
|
String | marshall(Object obj) marshall JAXBContext context = JAXBContext.newInstance(obj.getClass()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter w = new StringWriter(); m.marshal(obj, w); return w.toString(); |
String | marshall(Object obj, URL schemaURL, Class... classesToBeBound) marshall JAXBContext context = JAXBContext.newInstance(classesToBeBound); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); if (schemaURL != null) { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(schemaURL); marshaller.setSchema(schema); StringWriter writer = new StringWriter(); marshaller.marshal(obj, writer); return writer.toString(); |
InputStream | marshall(Object toMarshall) Marshalls the object to a String. StringWriter sw = null; try { JAXBContext ctx = JAXBContext.newInstance(toMarshall.getClass().getPackage().getName()); sw = new StringWriter(); Marshaller marshaller = ctx.createMarshaller(); marshaller.setProperty("jaxb.formatted.output", true); marshaller.marshal(toMarshall, sw); } catch (Exception e) { ... |
void | marshall(OutputStream os, JAXBElement marshall JAXBContext context = JAXBContext.newInstance(element.getDeclaredType()); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(element, os); |
void | marshall(String cntxtPkg, Object obj, OutputStream out) marshall Marshaller marshaller = createMarshall(cntxtPkg); if (marshaller == null) return; marshaller.marshal(obj, out); |
void | marshall(String file, JAXBElement marshall JAXBContext ctx = JAXBContext.newInstance(context);
Marshaller marshaller = ctx.createMarshaller();
marshaller.marshal(object, new File(file));
|
String | marshaller(Object o, Class> T) marshaller JAXBContext jc; Marshaller marshaller; StringWriter writer = new StringWriter(); try { jc = JAXBContext.newInstance(T); marshaller = jc.createMarshaller(); marshaller.marshal(o, writer); } catch (JAXBException e) { ... |
void | marshaller(Object obj, File file) marshaller JAXBContext jc = JAXBContext.newInstance(obj.getClass()); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(obj, file); |
String | marshallerObject(Class c, Object o) marshaller Object String s = "<?xml version=\"1.0\" ?>"; try { JAXBContext jaxbContext = JAXBContext.newInstance(c); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "utf-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); StringWriter baos = new StringWriter(); ... |