List of utility methods to do XML JAXB Marshaller
void | marshal(Object object, OutputStream stream) Marshal an arbitrary object with JAXB. JAXB.marshal(object, stream); stream.close(); |
void | marshal(Object objectToMarshal) Marshal the provided object using System.out marshal(objectToMarshal, System.out); |
String | marshal(Object source, Class marshal JAXBContext jAXBContext = JAXBContext.newInstance(configurationClass); StringWriter writer = new StringWriter(); jAXBContext.createMarshaller().marshal(source, writer); return writer.toString(); |
String | marshal(T bean, Class>... bc) Convert a bean to XML format using JAXB. assert bean != null; Class<?>[] bind; if (bc.length > 0) { bind = new Class<?>[bc.length + 1]; bind[0] = bean.getClass(); for (int i = 0; i < bc.length; i++) bind[i + 1] = bc[i]; } else ... |
String | marshal(T clazz) Marshal an entity class into a XML String representation. JAXBContext jaxbContext = JAXBContext.newInstance(clazz.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter stringWriter = new StringWriter(); marshaller.marshal(clazz, stringWriter); return stringWriter.toString(); |
String | marshal(T object) marshal Class<T> clzz = (Class<T>) object.getClass(); JAXBContext context; context = JAXBContext.newInstance(clzz); Marshaller m = context.createMarshaller(); ByteArrayOutputStream os = new ByteArrayOutputStream(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(object, os); return os.toString(); ... |
String | marshal(T t, Class marshal StringWriter sw = new StringWriter(); try { JAXBContext jaxbContext = JAXBContext.newInstance(entityClass); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name()); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(t, sw); } catch (JAXBException e) { ... |
String | marshalAsString(Class clz, T marshalObj) marshal As String JAXBContext context = JAXBContext.newInstance(clz); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter writer = new StringWriter(); marshaller.marshal(marshalObj, new BufferedWriter(writer)); return writer.toString(); |
T | marshall(Class marshall T res; if (c == xml.getClass()) { res = (T) xml; } else { JAXBContext ctx = JAXBContext.newInstance(c); Unmarshaller unmarshaller = ctx.createUnmarshaller(); res = (T) unmarshaller.unmarshal(new StringReader(xml)); return res; |
String | marshall(final Object o, Class> clazz) Marshalls the given JaxB class into a XML document while explicitly providing the class Marshaller m; try { m = JAXBContext.newInstance(clazz).createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); final StringWriter w = new StringWriter(); m.marshal(o, w); return w.toString(); } catch (JAXBException e) { ... |