public static void toJson(Metadata metadata, Writer writer) throws IOException {
        if (metadata == null) {
            writer.write("null");
            return;
        }
        long max = TikaConfig.getMaxJsonStringFieldLength();
        try (JsonGenerator jsonGenerator = new JsonFactory()
                .setStreamReadConstraints(StreamReadConstraints
                        .builder()
                        .maxStringLength(TikaConfig.getMaxJsonStringFieldLength())
                        .build())
                .createGenerator(CloseShieldWriter.wrap(writer))) {
            if (PRETTY_PRINT) {
                jsonGenerator.useDefaultPrettyPrinter();
            }
            writeMetadataObject(metadata, jsonGenerator, PRETTY_PRINT);
        }
    }
Serializes a Metadata object to Json.  This does not flush or close the writer.

@param metadata metadata to write
@param writer   writer
@throws java.io.IOException if there is an IOException during writing
tika-serialization/src/main/java/org/apache/tika/serialization/JsonMetadata.java