@Override
    public void serialize(CaseInsensitiveStringMultiMap map, JsonGenerator gen, SerializerProvider serializers)
            throws IOException, JsonProcessingException {
        gen.writeStartObject(); // {

        for (String key : map.keySet()) {
            List<String> values = map.getAll(key);

            if (values.size() <= 1) {
                gen.writeStringField(key, values.get(0)); // "key": "value"
            } else {
                gen.writeFieldName(key); // "key":
                gen.writeStartArray(values.size()); // [
                for (String val : values) {
                    gen.writeString(val); // "value", ...
                }
                gen.writeEndArray();// ]
            }
        }

        gen.writeEndObject(); // }
    }
@see com.fasterxml.jackson.databind.JsonSerializer#serialize(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider)
gateway/engine/beans/src/main/java/io/apiman/gateway/engine/beans/util/MultiMapSerializer.java