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.git
The following commit(s) were added to refs/heads/main by this push:
new 103ed0c5f chore(Java): Update java quickstart doc, for note register
order-sensitive (#2837)
103ed0c5f is described below
commit 103ed0c5f5e54b01a296066efe768770083b80a0
Author: monk <[email protected]>
AuthorDate: Tue Nov 4 13:02:00 2025 +0800
chore(Java): Update java quickstart doc, for note register order-sensitive
(#2837)
<!--
**Thanks for contributing to Apache Fory™.**
**If this is your first time opening a PR on fory, you can refer to
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).**
Contribution Checklist
- The **Apache Fory™** community has requirements on the naming of pr
titles. You can also find instructions in
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).
- Apache Fory™ has a strong focus on performance. If the PR you submit
will have an impact on performance, please benchmark it first and
provide the benchmark result here.
-->
## Why?
<!-- Describe the purpose of this PR. -->
## What does this PR do?
Update java quickstart doc, for note register order-sensitive
<!-- Describe the details of this PR. -->
## Related issues
[](url)https://github.com/apache/fory/issues/2818
<!--
Is there any related issue? If this PR closes them you say say
fix/closes:
- #xxxx0
- #xxxx1
- Fixes #xxxx2
-->
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/fory/issues/new/choose) describing the
need to do so and update the document if necessary.
Delete section if not applicable.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
Delete section if not applicable.
-->
---------
Co-authored-by: Shawn Yang <[email protected]>
---
README.md | 1 +
docs/guide/java_serialization_guide.md | 1 +
.../src/main/java/org/apache/fory/BaseFory.java | 47 ++++++++++++++--------
3 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index 2b3f2c21f..083b6672b 100644
--- a/README.md
+++ b/README.md
@@ -222,6 +222,7 @@ public class Example {
// replace `build` with `buildThreadSafeFory` for Thread-Safe Usage
.build();
// Register your classes (required when class registration is enabled)
+ // Registration order must be consistent if id is not specified
fory.register(Person.class);
// Serialize
Person person = new Person();
diff --git a/docs/guide/java_serialization_guide.md
b/docs/guide/java_serialization_guide.md
index 5b053dfa6..bb1791d55 100644
--- a/docs/guide/java_serialization_guide.md
+++ b/docs/guide/java_serialization_guide.md
@@ -47,6 +47,7 @@ public class Example {
.build();
// Registering types can reduce class name serialization overhead, but not
mandatory.
// If class registration enabled, all custom types must be registered.
+ // Registration order must be consistent if id is not specified
fory.register(SomeClass.class);
byte[] bytes = fory.serialize(object);
System.out.println(fory.deserialize(bytes));
diff --git a/java/fory-core/src/main/java/org/apache/fory/BaseFory.java
b/java/fory-core/src/main/java/org/apache/fory/BaseFory.java
index 8d6b3c103..b5150d9e9 100644
--- a/java/fory-core/src/main/java/org/apache/fory/BaseFory.java
+++ b/java/fory-core/src/main/java/org/apache/fory/BaseFory.java
@@ -33,21 +33,28 @@ import org.apache.fory.serializer.Serializers;
public interface BaseFory {
/**
- * Register class and allocate an auto-grown ID for this class. Note that
the registration order
- * is important. If registration order is inconsistent, the allocated ID
will be different, and
- * the deserialization will failed.
+ * Register class and allocate an auto-grown ID for this class.
+ *
+ * <p><b>NOTE</b>: The registration order is important. If registration
order is inconsistent, the
+ * allocated ID will be different, and the deserialization will failed !!!
*
* @param cls class to register.
*/
void register(Class<?> cls);
- /** register class with given id. */
+ /**
+ * register class with given id.
+ *
+ * <p><b>NOTE</b>: The registration id is important. If registration id is
inconsistent, and the
+ * deserialization will failed !!!
+ */
void register(Class<?> cls, int id);
/**
- * Register class and allocate an auto-grown ID for this class. Note that
the registration order
- * is important. If registration order is inconsistent, the allocated ID
will be different, and
- * the deserialization will failed.
+ * Register class and allocate an auto-grown ID for this class.
+ *
+ * <p><b>NOTE</b>: The registration order is important. If registration
order is inconsistent, the
+ * allocated ID will be different, and the deserialization will failed !!!
*
* @param cls class to register.
* @param createSerializer whether to create serializer, if true and codegen
enabled, this will
@@ -79,9 +86,10 @@ public interface BaseFory {
void register(Class<?> cls, String namespace, String typeName);
/**
- * Register class and allocate an auto-grown ID for this class. Note that
the registration order
- * is important. If registration order is inconsistent, the allocated ID
will be different, and
- * the deserialization will failed.
+ * Register class and allocate an auto-grown ID for this class.
+ *
+ * <p><b>NOTE</b>: The registration order is important. If registration
order is inconsistent, the
+ * allocated ID will be different, and the deserialization will failed !!!
*
* @param className full class name to register.
*/
@@ -98,8 +106,10 @@ public interface BaseFory {
/**
* Register a Serializer for a class, and allocate an auto-grown ID for this
class if it's not
- * registered yet. Note that the registration order is important. If
registration order is
- * inconsistent, the allocated ID will be different, and the deserialization
will failed.
+ * registered yet.
+ *
+ * <p><b>NOTE</b>: The registration order is important. If registration
order is inconsistent, the
+ * allocated ID will be different, and the deserialization will failed !!!
*
* @param type class needed to be serialized/deserialized.
* @param serializerClass serializer class can be created with {@link
Serializers#newSerializer}.
@@ -109,16 +119,19 @@ public interface BaseFory {
/**
* Register a Serializer for a class, and allocate an auto-grown ID for this
class if it's not
- * registered yet. Note that the registration order is important. If
registration order is
- * inconsistent, the allocated ID will be different, and the deserialization
will failed.
+ * registered yet.
+ *
+ * <p><b>NOTE</b>: The registration order is important. If registration
order is inconsistent, the
+ * allocated ID will be different, and the deserialization will failed !!!
*/
void registerSerializer(Class<?> type, Serializer<?> serializer);
/**
* Register a Serializer created by serializerCreator when fory created. And
allocate an
- * auto-grown ID for this class if it's not registered yet. Note that the
registration order is
- * important. If registration order is inconsistent, the allocated ID will
be different, and the
- * deserialization will failed.
+ * auto-grown ID for this class if it's not registered yet.
+ *
+ * <p><b>NOTE</b>: The registration order is important. If registration
order is inconsistent, the
+ * allocated ID will be different, and the deserialization will failed !!!
*
* @param type class needed to be serialized/deserialized.
* @param serializerCreator serializer creator with param {@link Fory}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]