Skip to content

refactor(java): refactor fory java serialization api#3537

Merged
chaokunyang merged 33 commits intoapache:mainfrom
chaokunyang:refactor_fory_java_serialization_api
Apr 6, 2026
Merged

refactor(java): refactor fory java serialization api#3537
chaokunyang merged 33 commits intoapache:mainfrom
chaokunyang:refactor_fory_java_serialization_api

Conversation

@chaokunyang
Copy link
Copy Markdown
Collaborator

@chaokunyang chaokunyang commented Apr 5, 2026

Why?

  • Prepare the Java serialization API for 1.0 by replacing ambient runtime state and legacy resolver/context APIs with a smaller, explicit operation-context model.
  • This is an intentional breaking Java API change. The refactor is necessary now so the pre-1.0 surface can be simplified, made more explicit, and stabilized before 1.0.
  • Remove dead or overlapping runtime layers that were making serializer ownership, codegen, GraalVM support, and downstream language integrations harder to maintain.

What does this PR do?

  • Refactors the Java serialization runtime around explicit WriteContext, ReadContext, CopyContext, RefReader, RefWriter, MetaStringReader, MetaStringWriter, MetaWriteContext, and MetaReadContext.
  • Removes the old ambient and legacy runtime pieces such as SerializationContext, RefResolver, MetaStringResolver, MetaStringRef, MapRefResolver, NoRefResolver, and ForwardSerializer.
  • Shrinks and cleans Fory, moves per-operation state out of the root runtime object, and rewires resolver, serializer, and codegen paths to use the explicit contexts.
  • Reworks serializer APIs and implementations across core, Kotlin, Scala, GraalVM examples, extensions, benchmarks, and docs to follow the new context-based surface and shareable() contract.
  • Simplifies meta-string and shared-runtime handling, including direct EncodedMetaString caching in SharedRegistry and context-owned read/write state.
  • Updates generated-code and builder paths plus downstream fixes so primitive-list serializers, replace/resolve serializers, GraalVM examples, Kotlin unsigned arrays, and Scala range serializers continue to work on the refactored API.

Related issues

#1017

AI Contribution Checklist

  • Substantial AI assistance was used in this PR: yes / no
  • If yes, I included a completed AI Contribution Checklist in this PR description and the required AI Usage Disclosure.

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

  • Updated the Java benchmark sources and benchmark state wiring to match the refactored API surface.

chaokunyang and others added 18 commits March 28, 2026 10:28
…lization_arc

# Conflicts:
#	docs/guide/java/configuration.md
#	docs/guide/java/index.md
#	docs/guide/java/schema-evolution.md
#	docs/guide/java/type-registration.md
#	java/fory-core/src/main/java/org/apache/fory/ThreadLocalFory.java
#	java/fory-core/src/main/java/org/apache/fory/ThreadSafeFory.java
#	java/fory-core/src/main/java/org/apache/fory/ThreadSafeForyPool.java
#	java/fory-core/src/main/java/org/apache/fory/config/ForyBuilder.java
#	java/fory-core/src/main/java/org/apache/fory/resolver/SharedRegistry.java
#	java/fory-core/src/main/java/org/apache/fory/serializer/ForwardSerializer.java
#	java/fory-core/src/main/resources/META-INF/native-image/org.apache.fory/fory-core/native-image.properties
#	java/fory-core/src/test/java/org/apache/fory/ThreadSafeForyTest.java
#	java/fory-core/src/test/java/org/apache/fory/builder/JITContextTest.java
#	java/fory-core/src/test/java/org/apache/fory/resolver/AllowListCheckerTest.java
#	java/fory-core/src/test/java/org/apache/fory/serializer/ForwardSerializerTest.java
#	java/fory-latest-jdk-tests/src/test/java/org/apache/fory/VirtualThreadSafeForyTest.java
@chaokunyang chaokunyang force-pushed the refactor_fory_java_serialization_api branch 3 times, most recently from 8172693 to f81aaa5 Compare April 5, 2026 13:12
@chaokunyang chaokunyang force-pushed the refactor_fory_java_serialization_api branch from f81aaa5 to c8ea40b Compare April 5, 2026 13:22
@chaokunyang chaokunyang force-pushed the refactor_fory_java_serialization_api branch from f26a803 to ff73c52 Compare April 5, 2026 13:45
@chaokunyang chaokunyang force-pushed the refactor_fory_java_serialization_api branch from 34b99aa to 52a2393 Compare April 5, 2026 14:13
@chaokunyang chaokunyang mentioned this pull request Apr 6, 2026
16 tasks
@chaokunyang chaokunyang merged commit 0a0fb53 into apache:main Apr 6, 2026
61 checks passed
chaokunyang added a commit that referenced this pull request Apr 8, 2026
## Why?

Refactor the Python serialization runtime to make serializer ownership
and per-operation state explicit. This moves read and write state out of
`Fory`, aligns the Python and Cython code paths around the same context
model, and simplifies how custom serializers interact with the runtime.


## What does this PR do?

- Introduces explicit `Config`, `WriteContext`, and `ReadContext`
runtime objects and moves serialization state management out of `Fory`.
- Refactors Python and Cython serializer APIs to take `type_resolver` in
constructors and to read or write through `read_context` and
`write_context` instead of raw buffer methods.
- Reorganizes the Python serialization implementation by moving
context-owned logic into `context.py` and `context.pxi`, slimming
`serialization.pyx`, and wiring collection, primitive, struct, union,
and registry paths through the new boundaries.
- Updates the Python custom serializer and type registration docs to the
new constructor and context-based serializer method signatures.
- Refreshes the affected Python tests to use the new serializer and
runtime context API shape.


## Related issues

#3537

## 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`.



## Does this PR introduce any user-facing change?

This refactor changes the Python custom serializer constructor and read
or write method signatures, and updates the Python docs accordingly.

- [x] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?

## Benchmark
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.

2 participants