Skip to content

Add SerializationFeature.ORDER_SET_ELEMENTS for #3166#5780

Merged
cowtowncoder merged 7 commits intoFasterXML:3.xfrom
dlwldnjs1009:fix/3166-order-set-entries-3x
Mar 22, 2026
Merged

Add SerializationFeature.ORDER_SET_ELEMENTS for #3166#5780
cowtowncoder merged 7 commits intoFasterXML:3.xfrom
dlwldnjs1009:fix/3166-order-set-entries-3x

Conversation

@dlwldnjs1009
Copy link
Copy Markdown
Contributor

@dlwldnjs1009 dlwldnjs1009 commented Mar 14, 2026

Fixes #3166

Retargeted to 3.x from #5776, per @cowtowncoder's suggestion.

Summary

  • Add SerializationFeature.ORDER_SET_ELEMENTS to sort eligible Set entries before serialization (disabled by default)
  • Add SerializationFeature.FAIL_ON_ORDER_SET_BY_INCOMPARABLE_ELEMENT to control handling of non-Comparable or mutually incomparable elements (disabled by default)
  • Apply ordering in both CollectionSerializer and StringCollectionSerializer, with an early Comparable pre-check in CollectionSerializer._orderElements similar to MapSerializer._orderEntries
  • Leave SortedSet and EnumSet unchanged

Test plan

  • Feature disabled: no sorting applied
  • Ordering for Set<Integer>, Set<String>, LinkedHashSet
  • SortedSet / EnumSet preserved as-is, including custom comparator order
  • Non-Comparable and mixed-type handling (fail/skip)
  • null elements, polymorphic serialization, custom content serializer fallback

This is a Phase 1, databind-only change. Per-property annotation support (JsonFormat.Feature) can follow separately.

@github-actions
Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.33% 📈 +0.000%
Branches branches 74.54% 📈 +0.010%

Coverage data generated from JaCoCo test results

@github-actions
Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.35% 📈 +0.010%
Branches branches 74.56% 📈 +0.030%

Coverage data generated from JaCoCo test results

Avoid sorting attempts for Sets whose elements are not `Comparable`,
and skip the temporary `ArrayList` allocation in that case.

This is similar to the early check used by `MapSerializer._orderEntries`,
while keeping the existing `ClassCastException` fallback for mixed
`Comparable` types.
@github-actions
Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.35% 📈 +0.000%
Branches branches 74.58% 📈 +0.010%

Coverage data generated from JaCoCo test results

@cowtowncoder cowtowncoder changed the title Add SerializationFeature.ORDER_SET_ENTRIES_BY_ELEMENTS for #3166 Add SerializationFeature.ORDER_SET_ELEMENTS for #3166 Mar 22, 2026
@github-actions
Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.35% 📈 +0.000%
Branches branches 74.59% 📈 +0.020%

Coverage data generated from JaCoCo test results

@github-actions
Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.35% 📈 +0.000%
Branches branches 74.59% 📈 +0.020%

Coverage data generated from JaCoCo test results

@github-actions
Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.35% 📈 +0.000%
Branches branches 74.56% 📉 -0.010%

Coverage data generated from JaCoCo test results

@github-actions
Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.36% 📈 +0.010%
Branches branches 74.61% 📈 +0.040%

Coverage data generated from JaCoCo test results

@cowtowncoder cowtowncoder merged commit 7fafcce into FasterXML:3.x Mar 22, 2026
6 checks passed
@dlwldnjs1009 dlwldnjs1009 deleted the fix/3166-order-set-entries-3x branch March 24, 2026 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to sort Sets before serialization (add SerializationFeature.ORDER_SET_ELEMENTS)

2 participants