class JAXBSupport {

    public static Marshaller createMarshaller(boolean includeProcessingInstruction) {
        Marshaller m;
        try {
            m = CONTEXT.createMarshaller();
            // pretty printed output is required as the XML is sent 1:1 to the browser for editing
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            try {
                m.setProperty("com.sun.xml.bind.namespacePrefixMapper", PREFIX_MAPPER);
            } catch (PropertyException e) {
                // Namespace-Prefixing is not supported by the used Provider. Nothing we can do about that
                LOGGER.debug("NamespacePrefixMapper could not be initialized!");
            }
            if (!includeProcessingInstruction) {
                // side effect of JAXB_FRAGMENT property (when true): processing instruction is not included
                m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
            }
        } catch (JAXBException e) {
            LOGGER.error("Could not instantiate marshaller", e);
            throw new IllegalStateException(e);
        }

        return m;
    }

}