Skip to content

Commit 4777250

Browse files
authored
fix(java): auto-select child serializers for sorted containers (#3552)
## Why? Auto serializer selection was falling back to JDK-compatible serializers for eligible sorted/container subclasses such as `TreeSet`, `TreeMap`, `ConcurrentSkipListSet`, `ConcurrentSkipListMap`, and `PriorityQueue`. That routed child containers through the inefficient `ObjectStreamSerializer` path even when the optimized child-container strategy could preserve both container state and subclass fields. ## What does this PR do? - extend `ChildContainerSerializers` with constructor-aware child serializers for sorted sets, sorted maps, and priority queues - teach auto-selection to use those serializers for eligible subclasses instead of the JDK-compatible fallback - register the new serializers in the builtin serializer factory and GraalVM defaults - add regression coverage for auto-selected sorted/container subclasses with preserved child state and comparator behavior ## Related issues Closes #3521. ## AI Contribution Checklist - [ ] Substantial AI assistance was used in this PR: `yes` / `no` - [ ] If `yes`, I included a completed [AI Contribution Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs) in this PR description and the required `AI Usage Disclosure`. - [ ] If `yes`, my PR description includes the required `ai_review` summary and screenshot evidence of the final clean AI review results from both fresh reviewers on the current PR diff or current HEAD after the latest code changes. ## Does this PR introduce any user-facing change? - [ ] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change?
1 parent d254818 commit 4777250

4 files changed

Lines changed: 565 additions & 20 deletions

File tree

java/fory-core/src/main/java/org/apache/fory/serializer/Serializers.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ private static <T> Serializer<T> buildBuiltinSerializer(
246246
if (serializerClass == ChildContainerSerializers.ChildMapSerializer.class) {
247247
return new ChildContainerSerializers.ChildMapSerializer(typeResolver, type);
248248
}
249+
if (serializerClass == ChildContainerSerializers.ChildSortedSetSerializer.class) {
250+
return new ChildContainerSerializers.ChildSortedSetSerializer(typeResolver, type);
251+
}
252+
if (serializerClass == ChildContainerSerializers.ChildPriorityQueueSerializer.class) {
253+
return new ChildContainerSerializers.ChildPriorityQueueSerializer(typeResolver, type);
254+
}
255+
if (serializerClass == ChildContainerSerializers.ChildSortedMapSerializer.class) {
256+
return new ChildContainerSerializers.ChildSortedMapSerializer(typeResolver, type);
257+
}
249258
if (serializerClass == SingletonCollectionSerializer.class) {
250259
return new SingletonCollectionSerializer(typeResolver, type);
251260
}

0 commit comments

Comments
 (0)