@Override
    public void serialize(HeaderMap 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(); // }
    }
@ Override public void serialize ( HeaderMap 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 ) ) ; } else { gen . writeFieldName ( key ) ; gen . writeStartArray ( values . size ( ) ) ; for ( String val : values ) { gen . writeString ( val ) ; } gen . writeEndArray ( ) ; } } gen . writeEndObject ( ) ; }
@see com.fasterxml.jackson.databind.JsonSerializer#serialize(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider)