private static void serializeCollection(String fieldName, Object obj, JsonGenerator jsonGenerator) throws IOException, TikaSerializationException {
        if (fieldName != null) {
            jsonGenerator.writeFieldName(fieldName);
        }
        Class clazz = obj.getClass();
        if (clazz.isArray()) {
            jsonGenerator.writeStartArray();
            for (Object item : (Object[]) obj) {
                serialize(item, jsonGenerator);
            }
            jsonGenerator.writeEndArray();
        } else if (List.class.isAssignableFrom(clazz)) {
            //should we get the generic type of the list via reflection
            //so that we can set the superclass field in the item?
            jsonGenerator.writeStartArray();
            for (Object item : (List) obj) {
                serialize(item, jsonGenerator);
            }
            jsonGenerator.writeEndArray();
        } else if (Map.class.isAssignableFrom(clazz)) {
            jsonGenerator.writeStartObject();
            for (Map.Entry<String, Object> e : ((Map<String, Object>) obj).entrySet()) {
                serialize(e.getKey(), e.getValue(), jsonGenerator);
            }
            jsonGenerator.writeEndObject();
        } else {
            throw new UnsupportedOperationException("Should have been a collection?! " + clazz);
        }
    }
@param fieldName     can be null -- used only for logging and debugging
@param obj
@param jsonGenerator
@throws TikaSerializationException
tika-serialization/src/main/java/org/apache/tika/serialization/TikaJsonSerializer.java