Java Utililty Methods XML JAXB Marshaller

List of utility methods to do XML JAXB Marshaller

Description

The list of methods to do XML JAXB Marshaller are organized into topic(s).

Method

voidmarshalPackage(OutputStream printStream, final Package p)
marshal Package
JAXBContext jc = JAXBContext.newInstance(ORG_ZEND_SDKLIB_DESCRIPTOR_PKG);
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(p, printStream);
StringmarshalToString(Object obj)
marshal To String
StringWriter stringWriter = new StringWriter();
JAXBContext jaxbContext = JAXBContext.newInstance(obj.getClass());
Marshaller marshaller = jaxbContext.createMarshaller();
JAXBElement jaxbElement = new JAXBElement(new QName("ROOT"), obj.getClass(), obj);
marshaller.marshal(jaxbElement, stringWriter);
return stringWriter.toString();
StringmarshalToString(Object obj)
marshal To String
StringWriter writer = new StringWriter();
JAXBContext jc = getContext(obj.getClass());
Marshaller marshaller = jc.createMarshaller();
marshaller.marshal(obj, writer);
return writer.toString();
StringmarshalV2(Class clazz, T obj, String uri, String nodeName)
marshal V
StringWriter out = new StringWriter();
JAXBContext context = JAXBContext.newInstance(clazz);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(new JAXBElement<T>(new QName(uri, nodeName), clazz, obj), out);
return out.toString();
voidremoveStandalone(final Marshaller marshaller)
remove Standalone
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
voidsetEncoding(@Nonnull final Marshaller aMarshaller, @Nullable final Charset aEncoding)
Set the standard property for the encoding charset.
setEncoding(aMarshaller, aEncoding == null ? null : aEncoding.name());
StringxmlMarshal(Object obj, Class clazz)
xml Marshal
StringWriter stringWriter = new StringWriter();
try {
    JAXBContext context = JAXBContext.newInstance(clazz);
    Marshaller marshaller = context.createMarshaller();
    marshaller.marshal(obj, stringWriter);
} catch (JAXBException e) {
    e.printStackTrace();
return stringWriter.toString();