public static <T extends FieldValue> void serializeWeightedSet(JsonGenerator generator, FieldBase field, WeightedSet<T> value) {
        // Hide empty fields
        if (value.size() == 0) {
            return;
        }
        fieldNameIfNotNull(generator, field);
        wrapIOException(() -> {
            generator.writeStartObject();

            for (T key : value.keySet()) {
                Integer weight = value.get(key);
                // key.toString() is according to spec
                generator.writeNumberField(key.toString(), weight);
            }

            generator.writeEndObject();
        });
    }
@author Steinar Knutsen
@author Vegard Sjonfjell
document/src/main/java/com/yahoo/document/json/JsonSerializationHelper.java