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

MarshallergetMarshaller()
get Marshaller
return jaxbContext.createMarshaller();
MarshallergetMarshaller()
get Marshaller
Marshaller m = marshaller.get();
if (m == null) {
    m = jaxbContext.createMarshaller();
    marshaller.set(m);
return m;
MarshallergetMarshaller(boolean prettyFormat)
get Marshaller
Marshaller m = jxbc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, prettyFormat);
m.setProperty("com.sun.xml.bind.indentString", "  ");
return m;
UnmarshallergetMarshaller(Class c)
get Marshaller
if (marshallerMap.containsKey(c)) {
    return marshallerMap.get(c);
} else {
    JAXBContext context = JAXBContext.newInstance(c);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    marshallerMap.put(c, unmarshaller);
    return unmarshaller;
MarshallergetMarshaller(Class clazz)
get Marshaller
Marshaller marshaller = marshallers.get(clazz);
if (marshaller == null)
    marshaller = createMarshaller(clazz);
return marshaller;
MarshallergetMarshaller(final String contextPath)
get Marshaller
final JAXBContext jaxbContext = JAXBContext.newInstance(contextPath);
final Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
return marshaller;
MarshallergetMarshaller(String jaxbContext, boolean pretty)
creates a marshaller on pooled JAXBContext instances.
JAXBContext context = null;
synchronized (contexts) {
    context = contexts.get(jaxbContext);
    if (null == context) {
        context = JAXBContext.newInstance(jaxbContext);
        contexts.put(jaxbContext, context);
Marshaller marshaller = null;
synchronized (context) {
    marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(pretty));
return marshaller;
StringgetSchemaLocation(@Nonnull final Marshaller aMarshaller)
get Schema Location
return _getStringProperty(aMarshaller, Marshaller.JAXB_SCHEMA_LOCATION);
ObjectgetSunNamespacePrefixMapper(@Nonnull final Marshaller aMarshaller)
get Sun Namespace Prefix Mapper
return _getProperty(aMarshaller, SUN_PREFIX_MAPPER);
booleanisInternalSunJAXB2Marshaller(@Nullable final Marshaller aMarshaller)
Check if the passed marshaller is an internal one contained in the runtime.
return aMarshaller != null && aMarshaller.getClass().getName().equals(JAXB_INTERNAL_CLASS_NAME);