jackson-datatypes-collections
jackson-datatypes-collections copied to clipboard
[guava] Add support for `WRITE_SORTED_MAP_ENTRIES`
Currently (2.7.5) MultimapSerializer
does not make use of either SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS
or JsonFormat.Feature.WRITE_SORTED_MAP_ENTRIES
; it should.
Hi, I was going to take a look at this as my first time contributing. I think i can re-create this as a failing test by creating a HashMultimap and inserting keys such as key-0, key-1, key-2. Then i configure the objectmapper with SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true
. Then on serialization, the json should maintain the keys natural ordering but it doesn't currently.
That sounds good. Alternatively if there is insertion-order-retaining variant, that might be best for repeatable test case; although if hash order is stable enough that should work.
There is a comment where this should be plugged in MultimapSerializer. I was thinking of doing
ImmutableSetMultimap<?, ? extends Collection<?>> immutableSortedMultimap = ImmutableSortedMap.copyOf(value.asMap()).asMultimap();
Where value is passed in is a HashMultimap
- the map is a String -> HashSet<String>
after the sorting immutableSortedMultimap
has a wrapped structure. the value is a SingletonImmutableSet
with the value being a set of a set. And the _valueSerializer is set to StringCollectionSerializer
Perhaps this is the wrong strategy to tackle this problem?
I haven't looked into this, and do not remember how Guava Multimaps work. Maybe someone else can help here.