Skip to content

feat(swift): dynamic any serializer for polymorphism#3368

Merged
chaokunyang merged 4 commits intoapache:mainfrom
chaokunyang:support_any_serialization_for_swift
Feb 19, 2026
Merged

feat(swift): dynamic any serializer for polymorphism#3368
chaokunyang merged 4 commits intoapache:mainfrom
chaokunyang:support_any_serialization_for_swift

Conversation

@chaokunyang
Copy link
Copy Markdown
Collaborator

@chaokunyang chaokunyang commented Feb 19, 2026

Why?

Swift xlang polymorphism currently relies on a custom AnyAnimal bridge in the peer, which makes dynamic payload handling narrow and hard to extend. This PR adds first-class dynamic Any serialization so polymorphic lists/maps can round-trip through the core runtime and macro-generated models directly.

What does this PR do?

  • Add AnySerializer.swift with runtime Any codec support, including dynamic type info read/write, null sentinel handling, and dynamic payload encode/decode helpers.
  • Add dynamic container helpers for [Any], [String: Any], and [Int32: Any] (including map key-type probing for dynamic map decode).
  • Expose WriteContext/ReadContext convenience APIs and new Fory overloads for serializing/deserializing dynamic Any collections in both buffer and stream-style entry points.
  • Extend TypeResolver to parse dynamic wire type metadata and decode dynamic values (primitive/array/list/map/registered types) by id or name, with registration-mode tracking.
  • Add RefReader.readRefValue(_:) support used by dynamic Any reference resolution.
  • Extend @ForyObject macro generation to support Any, [Any], [String: Any], and [Int32: Any] fields with generated read/write paths and compatibility metadata handling; reject unsupported Set<Any> and unsupported dictionary key types.
  • Simplify ForySwiftXlangPeer polymorphic handlers by removing the custom AnyAnimal codec and switching to native [Any] / [String: Any] round-trips.

Related issues

Closes #3367
#1017 #3349

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?

Benchmark

@chaokunyang chaokunyang changed the title feat(swift): implement dynamic Any serializer for xlang polymorphism feat(swift): dynamic any serializer for polymorphism Feb 19, 2026
@chaokunyang chaokunyang merged commit a9d1720 into apache:main Feb 19, 2026
60 checks passed
@chaokunyang chaokunyang mentioned this pull request Feb 20, 2026
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Swift] Support polymorphic serialization: Any, AnyObject and any protocol

2 participants