public static void serialize(TikaConfig config, Mode mode, Writer writer, Charset charset)
            throws Exception {
        DocumentBuilder docBuilder = XMLReaderUtils.getDocumentBuilder();

        // root elements
        Document doc = docBuilder.newDocument();
        Element rootElement = doc.createElement("properties");

        doc.appendChild(rootElement);
        addMimeComment(mode, rootElement, doc);
        addServiceLoader(mode, rootElement, doc, config);
        addExecutorService(mode, rootElement, doc, config);
        addEncodingDetectors(mode, rootElement, doc, config);
        addTranslator(mode, rootElement, doc, config);
        addDetectors(mode, rootElement, doc, config);
        addParsers(mode, rootElement, doc, config);
        // TODO Service Loader section

        // now write
        Transformer transformer = XMLReaderUtils.getTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.setOutputProperty(OutputKeys.ENCODING, charset.name());
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(writer);

        transformer.transform(source, result);
    }
@Test
    public void testMultipleWithFallback() throws Exception {
        TikaConfig config = getConfig("TIKA-1509-multiple-fallback.xml");
        StringWriter writer = new StringWriter();
        TikaConfigSerializer.serialize(config,
                TikaConfigSerializer.Mode.STATIC_FULL, writer, StandardCharsets.UTF_8);
        try (InputStream is =
                     new ByteArrayInputStream(writer.toString().getBytes(StandardCharsets.UTF_8))) {
            config = new TikaConfig(is);
        }

        CompositeParser parser = (CompositeParser) config.getParser();
        assertEquals(2, parser.getAllComponentParsers().size());
        Parser p;

        p = parser.getAllComponentParsers().get(0);
        assertEquals(MockParser.class, ((ParserDecorator) p).getWrappedParser().getClass());

        p = parser.getAllComponentParsers().get(1);
        assertTrue(p instanceof ParserDecorator, p.toString());
        assertEquals(FallbackParser.class, ((ParserDecorator) p).getWrappedParser().getClass());

        FallbackParser fbp = (FallbackParser) ((ParserDecorator) p).getWrappedParser();
        assertEquals("DISCARD_ALL", fbp.getMetadataPolicy().toString());
    }