Add SerializationFeature.ORDER_SET_ENTRIES_BY_ELEMENTS for #3166#5776
Closed
dlwldnjs1009 wants to merge 2 commits intoFasterXML:2.xfrom
Closed
Add SerializationFeature.ORDER_SET_ENTRIES_BY_ELEMENTS for #3166#5776dlwldnjs1009 wants to merge 2 commits intoFasterXML:2.xfrom
dlwldnjs1009 wants to merge 2 commits intoFasterXML:2.xfrom
Conversation
Support deterministic Set serialization with a new SerializationFeature and tests for String and general Collection paths.
Verify that SortedSet with a custom comparator (e.g. reverseOrder) preserves its own ordering when the feature is enabled.
Member
|
We are trying to stop adding new features in 2.x and mostly just apply fixes so I think this should go against 3.x. |
Contributor
Author
|
Closing this in favor of a new PR against |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This adds a Phase 1 implementation for #3166 by introducing global Set ordering during serialization.
SerializationFeature.ORDER_SET_ENTRIES_BY_ELEMENTS(disabled by default)SerializationFeature.FAIL_ON_ORDER_SET_BY_INCOMPARABLE_ELEMENT(enabled by default)CollectionSerializerandStringCollectionSerializerImplementation notes
Set<String>takes the specializedStringCollectionSerializerpath, while other Set types useCollectionSerializer, so both serializers need the ordering hook.The hook is placed in
serializeContents(), which also covers theserializeWithType()path becauseAsArraySerializerBasedelegates there directly.SortedSetandEnumSetare left as-is.For incomparable elements, the implementation attempts sorting and catches
ClassCastException.FAIL_ON_ORDER_SET_BY_INCOMPARABLE_ELEMENTcontrols whether serialization should fail or simply skip sorting.Tests
Adds
CollectionSerializationOrderTestcovering:SortedSetandEnumSetOut of scope
Per-property annotation support (
JsonFormat.Featurecounterpart) is intentionally deferred to a follow-up change.