private static void serializePrimitives(Document doc, Element root,
                                            Object object,
                                            MethodTuples setterTuples, MethodTuples getterTuples) {

        Element paramsElement = null;
        if (object instanceof AbstractMultipleParser) {
            paramsElement = doc.createElement("params");
            Element paramElement = doc.createElement("param");
            paramElement.setAttribute("name", "metadataPolicy");
            paramElement.setAttribute("value",
                    ((AbstractMultipleParser) object).getMetadataPolicy().toString());
            paramsElement.appendChild(paramElement);
            root.appendChild(paramsElement);
        }
        for (Map.Entry<String, Set<MethodTuple>> e : setterTuples.tuples.entrySet()) {
            if (!getterTuples.tuples.containsKey(e.getKey())) {
                LOG.info("no getter for setter: {} in {}", e.getKey(), object.getClass());
                continue;
            }
            Set<MethodTuple> getters = getterTuples.tuples.get(e.getKey());
            Set<MethodTuple> setters = e.getValue();
            MethodTuple getterTuple = null;
            for (MethodTuple getterCandidate : getters) {
                for (MethodTuple setter : setters) {
                    if (getterCandidate.singleParam.equals(setter.singleParam)) {
                        getterTuple = getterCandidate;
                        break;
                    }
                }
            }

            if (getterTuple == null) {
                LOG.debug("Could not find getter to match setter for: {}", e.getKey());
                continue;
            }
            Object value = null;
            try {
                value = getterTuple.method.invoke(object);
            } catch (IllegalAccessException ex) {
                LOG.error("couldn't invoke " + getterTuple, ex);
                continue;
            } catch (InvocationTargetException ex) {
                LOG.error("couldn't invoke " + getterTuple, ex);
                continue;
            }
            if (value == null) {
                LOG.debug("null value: {} in {}", getterTuple.name, object.getClass());
            }
            String valString = (value == null) ? "" : value.toString();
            Element param = doc.createElement("param");
            param.setAttribute("name", getterTuple.name);
            param.setAttribute("type", PRIMITIVES.get(getterTuple.singleParam));
            if (List.class.isAssignableFrom(getterTuple.singleParam)) {
                //this outputs even empty list elements, which I think is good.
                addList(param, doc, getterTuple, (List<String>) value);
            } else if (Map.class.isAssignableFrom(getterTuple.singleParam)) {
                //this outputs even empty lists, which I think is good.
                addMap(param, doc, getterTuple, (Map<String, String>) value);
            } else {
                param.setTextContent(valString);
            }
            if (paramsElement == null) {
                paramsElement = doc.createElement("params");
                root.appendChild(paramsElement);
            }
            paramsElement.appendChild(param);
        }
    }
@param config  config to serialize
@param mode    serialization mode
@param writer  writer
@param charset charset
@throws Exception
tika-core/src/main/java/org/apache/tika/config/TikaConfigSerializer.java