This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory-site.git
The following commit(s) were added to refs/heads/main by this push:
new f08e5324d5 🔄 synced local 'docs/guide/' with remote 'docs/guide/'
f08e5324d5 is described below
commit f08e5324d5255778b165d3e180a58f1e617e635f
Author: chaokunyang <[email protected]>
AuthorDate: Thu Apr 9 14:06:44 2026 +0000
🔄 synced local 'docs/guide/' with remote 'docs/guide/'
---
docs/guide/java/custom-serializers.md | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/docs/guide/java/custom-serializers.md
b/docs/guide/java/custom-serializers.md
index a1aee2f601..34bd73750d 100644
--- a/docs/guide/java/custom-serializers.md
+++ b/docs/guide/java/custom-serializers.md
@@ -27,8 +27,8 @@ Custom serializers should not retain `Fory`.
- Use `Config` when the serializer only depends on immutable configuration and
can be shared.
- Use `TypeResolver` when the serializer needs type metadata, generics, or
nested dynamic dispatch.
-- If a serializer retains `TypeResolver`, it is usually not shareable and
should keep the default
- `shareable() == false`.
+- If a serializer retains `TypeResolver`, it is usually not shareable and
should not implement
+ `Shareable`.
## Basic Serializer
@@ -41,8 +41,9 @@ import org.apache.fory.context.ReadContext;
import org.apache.fory.context.WriteContext;
import org.apache.fory.memory.MemoryBuffer;
import org.apache.fory.serializer.Serializer;
+import org.apache.fory.serializer.Shareable;
-public final class FooSerializer extends Serializer<Foo> {
+public final class FooSerializer extends Serializer<Foo> implements Shareable {
public FooSerializer(Config config) {
super(config, Foo.class);
}
@@ -61,11 +62,6 @@ public final class FooSerializer extends Serializer<Foo> {
foo.f2 = readContext.readString(buffer);
return foo;
}
-
- @Override
- public boolean shareable() {
- return true;
- }
}
```
@@ -108,7 +104,7 @@ public final class EnvelopeSerializer extends
Serializer<Envelope> {
}
```
-This serializer can be shareable because it retains no runtime-local mutable
state.
+This serializer can implement `Shareable` because it retains no runtime-local
mutable state.
## Collection Serializers
@@ -218,9 +214,10 @@ fory.registerSerializer(
## Shareability
-Override `shareable()` only when the serializer can be safely reused across
equivalent runtimes and
-concurrent operations. In practice, that means the serializer must not retain
operation state,
-runtime-local mutable state, or mutable scratch buffers that are shared across
calls.
+Implement the `Shareable` marker interface when the serializer can be safely
reused across
+equivalent runtimes and concurrent operations. A shareable serializer must not
retain operation
+state, runtime-local mutable state, or mutable scratch buffers shared across
calls. Consumers can
+check shareability via `serializer instanceof Shareable`.
In practice:
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]