jackson-datatypes-collections icon indicating copy to clipboard operation
jackson-datatypes-collections copied to clipboard

[guava] Add support for `WRITE_SORTED_MAP_ENTRIES`

Open cowtowncoder opened this issue 8 years ago • 4 comments

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.

cowtowncoder avatar May 19 '16 15:05 cowtowncoder

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.

sukhrajm avatar Oct 26 '20 14:10 sukhrajm

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.

cowtowncoder avatar Oct 27 '20 21:10 cowtowncoder

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?

sukhrajm avatar Oct 29 '20 21:10 sukhrajm

I haven't looked into this, and do not remember how Guava Multimaps work. Maybe someone else can help here.

cowtowncoder avatar Nov 03 '20 03:11 cowtowncoder