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
commit 285b75dbc286e0e1fbd0d8e4be5b701c60547c8c Author: chaokunyang <[email protected]> AuthorDate: Wed Apr 29 06:24:44 2026 +0000 π synced local 'docs/guide/' with remote 'docs/guide/' --- docs/guide/cpp/cross-language.md | 3 +- docs/guide/cpp/schema-evolution.md | 4 +- docs/guide/csharp/cross-language.md | 2 +- docs/guide/dart/cross-language.md | 2 +- docs/guide/dart/troubleshooting.md | 2 +- docs/guide/go/schema-evolution.md | 2 +- docs/guide/java/advanced-features.md | 4 +- docs/guide/java/basic-serialization.md | 12 +-- docs/guide/java/compression.md | 6 +- docs/guide/java/configuration.md | 56 ++++++------ docs/guide/java/cross-language.md | 12 +-- docs/guide/java/custom-serializers.md | 8 +- docs/guide/java/enum-configuration.md | 2 +- docs/guide/java/field-configuration.md | 123 ++++++++++++++++++--------- docs/guide/java/index.md | 26 +++--- docs/guide/java/object-copy.md | 12 +-- docs/guide/java/schema-evolution.md | 24 +++--- docs/guide/java/troubleshooting.md | 18 ++-- docs/guide/java/type-registration.md | 2 +- docs/guide/javascript/troubleshooting.md | 2 +- docs/guide/kotlin/default-values.md | 7 +- docs/guide/kotlin/fory-creation.md | 3 +- docs/guide/python/cross-language.md | 2 +- docs/guide/rust/cross-language.md | 2 +- docs/guide/rust/field-configuration.md | 4 +- docs/guide/scala/default-values.md | 11 ++- docs/guide/scala/fory-creation.md | 3 +- docs/guide/xlang/field-nullability.md | 2 +- docs/guide/xlang/field-reference-tracking.md | 4 +- docs/guide/xlang/getting-started.md | 4 +- docs/guide/xlang/index.md | 2 +- docs/guide/xlang/serialization.md | 6 +- docs/guide/xlang/troubleshooting.md | 4 +- docs/guide/xlang/zero-copy.md | 2 +- 34 files changed, 205 insertions(+), 173 deletions(-) diff --git a/docs/guide/cpp/cross-language.md b/docs/guide/cpp/cross-language.md index b0f308b5b..f9540c5e9 100644 --- a/docs/guide/cpp/cross-language.md +++ b/docs/guide/cpp/cross-language.md @@ -86,7 +86,6 @@ int main() { ```java import org.apache.fory.Fory; -import org.apache.fory.config.Language; public class Message { public String topic; @@ -98,7 +97,7 @@ public class Message { public class Consumer { public static void main(String[] args) throws Exception { Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .build(); fory.register(Message.class, 100); // Same ID as C++ diff --git a/docs/guide/cpp/schema-evolution.md b/docs/guide/cpp/schema-evolution.md index 84cf354b9..b91441521 100644 --- a/docs/guide/cpp/schema-evolution.md +++ b/docs/guide/cpp/schema-evolution.md @@ -402,8 +402,8 @@ auto fory = Fory::builder() ```java // Java with compatible mode Fory fory = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE) - .withLanguage(Language.XLANG) + .withCompatible(true) + .withXlang(true) .build(); ``` diff --git a/docs/guide/csharp/cross-language.md b/docs/guide/csharp/cross-language.md index a1c8af945..2520c7dea 100644 --- a/docs/guide/csharp/cross-language.md +++ b/docs/guide/csharp/cross-language.md @@ -71,7 +71,7 @@ byte[] payload = fory.Serialize(person); ```java Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .withRefTracking(true) .build(); diff --git a/docs/guide/dart/cross-language.md b/docs/guide/dart/cross-language.md index a4554b8c4..ed843d3d3 100644 --- a/docs/guide/dart/cross-language.md +++ b/docs/guide/dart/cross-language.md @@ -88,7 +88,7 @@ final bytes = fory.serialize(Person() ```java Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .build(); fory.register(Person.class, 100); diff --git a/docs/guide/dart/troubleshooting.md b/docs/guide/dart/troubleshooting.md index 95e2c1776..43df08e61 100644 --- a/docs/guide/dart/troubleshooting.md +++ b/docs/guide/dart/troubleshooting.md @@ -25,7 +25,7 @@ This page covers common Dart runtime issues and fixes. The writer is sending a native-mode (non-xlang) payload. Make sure every service uses the xlang-compatible path: -- **Java**: add `.withLanguage(Language.XLANG)` to the Fory builder. +- **Java**: add `.withXlang(true)` to the Fory builder. - **Go**: use `WithXlang(true)` in the Fory options. - **Other runtimes**: check their respective guides for enabling cross-language mode. diff --git a/docs/guide/go/schema-evolution.md b/docs/guide/go/schema-evolution.md index eea486e00..708290dc5 100644 --- a/docs/guide/go/schema-evolution.md +++ b/docs/guide/go/schema-evolution.md @@ -243,7 +243,7 @@ public class Message { Fory fory = Fory.builder() .withXlang(true) - .withCompatibleMode(true) + .withCompatible(true) .build(); fory.register(Message.class, 1); Message msg = fory.deserialize(data, Message.class); diff --git a/docs/guide/java/advanced-features.md b/docs/guide/java/advanced-features.md index 765b00247..7337643f4 100644 --- a/docs/guide/java/advanced-features.md +++ b/docs/guide/java/advanced-features.md @@ -37,7 +37,7 @@ import java.util.stream.Collectors; public class ZeroCopyExample { // Note that fory instance should be reused instead of creation every time. static Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .build(); public static void main(String[] args) { @@ -129,7 +129,7 @@ MemoryAllocator customAllocator = new MemoryAllocator() { MemoryBuffer.setGlobalAllocator(customAllocator); // All subsequent MemoryBuffer allocations will use your custom allocator -Fory fory = Fory.builder().withLanguage(Language.JAVA).build(); +Fory fory = Fory.builder().withXlang(false).build(); byte[] bytes = fory.serialize(someObject); // Uses custom allocator ``` diff --git a/docs/guide/java/basic-serialization.md b/docs/guide/java/basic-serialization.md index abc6d58dc..196a2073e 100644 --- a/docs/guide/java/basic-serialization.md +++ b/docs/guide/java/basic-serialization.md @@ -29,14 +29,14 @@ For single-threaded applications: ```java Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) // enable reference tracking for shared/circular reference. // Disable it will have better performance if no duplicate reference. .withRefTracking(false) - .withCompatibleMode(CompatibleMode.SCHEMA_CONSISTENT) + .withCompatible(false) // enable type forward/backward compatibility // disable it for small size and better performance. - // .withCompatibleMode(CompatibleMode.COMPATIBLE) + // .withCompatible(true) // enable async multi-threaded compilation. .withAsyncCompilation(true) .build(); @@ -50,7 +50,7 @@ For multi-threaded applications: ```java ThreadSafeFory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) // enable reference tracking for shared/circular reference. // Disable it will have better performance if no duplicate reference. .withRefTracking(false) @@ -58,10 +58,10 @@ ThreadSafeFory fory = Fory.builder() // .withIntCompressed(true) // compress long for smaller size // .withLongCompressed(true) - .withCompatibleMode(CompatibleMode.SCHEMA_CONSISTENT) + .withCompatible(false) // enable type forward/backward compatibility // disable it for small size and better performance. - // .withCompatibleMode(CompatibleMode.COMPATIBLE) + // .withCompatible(true) // enable async multi-threaded compilation. .withAsyncCompilation(true) .buildThreadSafeFory(); diff --git a/docs/guide/java/compression.md b/docs/guide/java/compression.md index 88cfb70a6..44be8f729 100644 --- a/docs/guide/java/compression.md +++ b/docs/guide/java/compression.md @@ -65,7 +65,7 @@ To enable array compression, you must explicitly register the serializers: ```java Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) // Enable int array compression .withIntArrayCompressed(true) // Enable long array compression @@ -114,14 +114,14 @@ String compression can be enabled via `ForyBuilder#withStringCompressed(true)`. ```java // For mostly numeric data - disable compression Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .withIntCompressed(false) .withLongCompressed(false) .build(); // For mixed data with arrays - enable array compression Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .withIntCompressed(true) .withLongCompressed(true) .withIntArrayCompressed(true) diff --git a/docs/guide/java/configuration.md b/docs/guide/java/configuration.md index dc1025bcd..3ae38b772 100644 --- a/docs/guide/java/configuration.md +++ b/docs/guide/java/configuration.md @@ -23,37 +23,37 @@ This page documents all configuration options available through `ForyBuilder`. ## ForyBuilder Options -| Option Name | Description [...] -| ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- [...] -| `timeRefIgnored` | Whether to ignore reference tracking of all time types registered in `TimeSerializers` and subclasses of those types when ref tracking is enabled. If ignored, ref tracking of every time type can be enabled by invoking `Fory#registerSerializer(Class, Serializer)`. For example, `fory.registerSerializer(Date.class, new DateSerializer(fory.getConfig(), true))`. Note that enabling ref tracking should happen before serializer codegen of any types which c [...] -| `compressInt` | Enables or disables int compression for smaller size. [...] -| `compressLong` | Enables or disables long compression for smaller size. [...] -| `compressIntArray` | Enables or disables SIMD-accelerated compression for int arrays when values can fit in smaller data types. Requires Java 16+. [...] -| `compressLongArray` | Enables or disables SIMD-accelerated compression for long arrays when values can fit in smaller data types. Requires Java 16+. [...] -| `compressString` | Enables or disables string compression for smaller size. [...] -| `classLoader` | The classloader is fixed per `Fory` instance because Fory caches class metadata. To use a different loader, create a new `Fory` or `ThreadSafeFory` configured with that loader, or rely on the thread context classloader before first class resolution. [...] -| `compatibleMode` | Type forward/backward compatibility config. Also Related to `checkClassVersion` config. `SCHEMA_CONSISTENT`: Class schema must be consistent between serialization peer and deserialization peer. `COMPATIBLE`: Class schema can be different between serialization peer and deserialization peer. They can add/delete fields independently. [See more](schema-evolution.md). [...] -| `checkClassVersion` | Determines whether to check the consistency of the class schema. If enabled, Fory checks, writes, and checks consistency using the `classVersionHash`. It will be automatically disabled when `CompatibleMode#COMPATIBLE` is enabled. Disabling is not recommended unless you can ensure the class won't evolve. [...] -| `checkJdkClassSerializable` | Enables or disables checking of `Serializable` interface for classes under `java.*`. If a class under `java.*` is not `Serializable`, Fory will throw an `UnsupportedOperationException`. [...] -| `registerGuavaTypes` | Whether to pre-register Guava types such as `RegularImmutableMap`/`RegularImmutableList`. These types are not public API, but seem pretty stable. [...] -| `requireClassRegistration` | Disabling may allow unknown classes to be deserialized, potentially causing security risks. [...] -| `maxDepth` | Set max depth for deserialization, when depth exceeds, an exception will be thrown. This can be used to refuse deserialization DDOS attack. [...] -| `suppressClassRegistrationWarnings` | Whether to suppress class registration warnings. The warnings can be used for security audit, but may be annoying, this suppression will be enabled by default. [...] -| `metaShareEnabled` | Enables or disables meta share mode. [...] -| `scopedMetaShareEnabled` | Scoped meta share focuses on a single serialization process. Metadata created or identified during this process is exclusive to it and is not shared with by other serializations. [...] -| `metaCompressor` | Set a compressor for meta compression. Note that the passed MetaCompressor should be thread-safe. By default, a `Deflater` based compressor `DeflaterMetaCompressor` will be used. Users can pass other compressor such as `zstd` for better compression rate. [...] -| `deserializeUnknownClass` | Enables or disables deserialization/skipping of data for non-existent or unknown classes. [...] -| `codeGenEnabled` | Disabling may result in faster initial serialization but slower subsequent serializations. [...] -| `asyncCompilationEnabled` | If enabled, serialization uses interpreter mode first and switches to JIT serialization after async serializer JIT for a class is finished. [...] -| `scalaOptimizationEnabled` | Enables or disables Scala-specific serialization optimization. [...] -| `copyRef` | When disabled, the copy performance will be better. But fory deep copy will ignore circular and shared reference. Same reference of an object graph will be copied into different objects in one `Fory#copy`. [...] -| `serializeEnumByName` | When enabled, Fory serializes enum names instead of numeric enum tags. Without this option, Fory writes declaration ordinals by default, or explicit stable ids when the enum is configured with `@ForyEnumId`. [...] +| Option Name | Description [...] +| ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- [...] +| `timeRefIgnored` | Whether to ignore reference tracking of all time types registered in `TimeSerializers` and subclasses of those types when ref tracking is enabled. If ignored, ref tracking of every time type can be enabled by invoking `Fory#registerSerializer(Class, Serializer)`. For example, `fory.registerSerializer(Date.class, new DateSerializer(fory.getConfig(), true))`. Note that enabling ref tracking should happen before serializer codegen of any types which c [...] +| `compressInt` | Enables or disables int compression for smaller size. [...] +| `compressLong` | Enables or disables long compression for smaller size. [...] +| `compressIntArray` | Enables or disables SIMD-accelerated compression for int arrays when values can fit in smaller data types. Requires Java 16+. [...] +| `compressLongArray` | Enables or disables SIMD-accelerated compression for long arrays when values can fit in smaller data types. Requires Java 16+. [...] +| `compressString` | Enables or disables string compression for smaller size. [...] +| `classLoader` | The classloader is fixed per `Fory` instance because Fory caches class metadata. To use a different loader, create a new `Fory` or `ThreadSafeFory` configured with that loader, or rely on the thread context classloader before first class resolution. [...] +| `compatible` | Type forward/backward compatibility config. `false`: class schema must be consistent between serialization peer and deserialization peer. `true`: class schema can be different between serialization peer and deserialization peer. They can add/delete fields independently. [See more](schema-evolution.md). [...] +| `checkClassVersion` | Determines whether to check the consistency of the class schema. If enabled, Fory checks, writes, and checks consistency using the `classVersionHash`. It will be automatically disabled when compatible mode is enabled. Disabling is not recommended unless you can ensure the class won't evolve. [...] +| `checkJdkClassSerializable` | Enables or disables checking of `Serializable` interface for classes under `java.*`. If a class under `java.*` is not `Serializable`, Fory will throw an `UnsupportedOperationException`. [...] +| `registerGuavaTypes` | Whether to pre-register Guava types such as `RegularImmutableMap`/`RegularImmutableList`. These types are not public API, but seem pretty stable. [...] +| `requireClassRegistration` | Disabling may allow unknown classes to be deserialized, potentially causing security risks. [...] +| `maxDepth` | Set max depth for deserialization, when depth exceeds, an exception will be thrown. This can be used to refuse deserialization DDOS attack. [...] +| `suppressClassRegistrationWarnings` | Whether to suppress class registration warnings. The warnings can be used for security audit, but may be annoying, this suppression will be enabled by default. [...] +| `metaShareEnabled` | Enables or disables meta share mode. [...] +| `scopedMetaShareEnabled` | Scoped meta share focuses on a single serialization process. Metadata created or identified during this process is exclusive to it and is not shared with by other serializations. [...] +| `metaCompressor` | Set a compressor for meta compression. Note that the passed MetaCompressor should be thread-safe. By default, a `Deflater` based compressor `DeflaterMetaCompressor` will be used. Users can pass other compressor such as `zstd` for better compression rate. [...] +| `deserializeUnknownClass` | Enables or disables deserialization/skipping of data for non-existent or unknown classes. [...] +| `codeGenEnabled` | Disabling may result in faster initial serialization but slower subsequent serializations. [...] +| `asyncCompilationEnabled` | If enabled, serialization uses interpreter mode first and switches to JIT serialization after async serializer JIT for a class is finished. [...] +| `scalaOptimizationEnabled` | Enables or disables Scala-specific serialization optimization. [...] +| `copyRef` | When disabled, the copy performance will be better. But fory deep copy will ignore circular and shared reference. Same reference of an object graph will be copied into different objects in one `Fory#copy`. [...] +| `serializeEnumByName` | When enabled, Fory serializes enum names instead of numeric enum tags. Without this option, Fory writes declaration ordinals by default, or explicit stable ids when the enum is configured with `@ForyEnumId`. [...] ## Example Configuration ```java Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) // enable reference tracking for shared/circular reference. // Disable it will have better performance if no duplicate reference. .withRefTracking(false) @@ -61,10 +61,10 @@ Fory fory = Fory.builder() .withIntCompressed(true) // compress long for smaller size .withLongCompressed(true) - .withCompatibleMode(CompatibleMode.SCHEMA_CONSISTENT) + .withCompatible(false) // enable type forward/backward compatibility // disable it for small size and better performance. - // .withCompatibleMode(CompatibleMode.COMPATIBLE) + // .withCompatible(true) // enable async multi-threaded compilation. .withAsyncCompilation(true) .build(); diff --git a/docs/guide/java/cross-language.md b/docs/guide/java/cross-language.md index 6309d25a6..e01f8258f 100644 --- a/docs/guide/java/cross-language.md +++ b/docs/guide/java/cross-language.md @@ -23,7 +23,7 @@ Apache Foryβ’ supports seamless data exchange between Java and other languages ## Enable Cross-Language Mode -To serialize data for consumption by other languages, use `Language.XLANG` mode: +To serialize data for consumption by other languages, enable xlang mode: ```java import org.apache.fory.*; @@ -31,7 +31,7 @@ import org.apache.fory.config.*; // Create Fory instance with XLANG mode Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .withRefTracking(true) // Enable reference tracking for complex graphs .build(); ``` @@ -85,7 +85,7 @@ public record Person(String name, int age) {} public class Example { public static void main(String[] args) { Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .withRefTracking(true) .build(); @@ -134,7 +134,7 @@ public class Node { } Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .withRefTracking(true) // Required for circular references .build(); @@ -195,7 +195,7 @@ Cross-language mode has additional overhead compared to Java-only mode: - Use **ID-based registration** when possible (smaller encoding) - **Disable reference tracking** if you don't need circular references (`withRefTracking(false)`) -- **Use Java mode** (`Language.JAVA`) when only Java serialization is needed +- **Use Java mode** (`withXlang(false)`) when only Java serialization is needed ## Cross-Language Best Practices @@ -216,7 +216,7 @@ Cross-language mode has additional overhead compared to Java-only mode: ### Data corruption or unexpected values -- Verify both sides use `Language.XLANG` mode +- Verify both sides enable xlang mode - Ensure both sides have compatible Fory versions ## See Also diff --git a/docs/guide/java/custom-serializers.md b/docs/guide/java/custom-serializers.md index 34bd73750..6079e176e 100644 --- a/docs/guide/java/custom-serializers.md +++ b/docs/guide/java/custom-serializers.md @@ -134,7 +134,7 @@ public final class CustomCollectionSerializer<T extends Collection<?>> @Override public Collection onCollectionWrite(WriteContext writeContext, T value) { - writeContext.getBuffer().writeVarUint32Small7(value.size()); + writeContext.getBuffer().writeVarUInt32Small7(value.size()); return value; } @@ -146,7 +146,7 @@ public final class CustomCollectionSerializer<T extends Collection<?>> @Override public Collection newCollection(ReadContext readContext) { MemoryBuffer buffer = readContext.getBuffer(); - int numElements = buffer.readVarUint32Small7(); + int numElements = buffer.readVarUInt32Small7(); setNumElements(numElements); return new ArrayList(numElements); } @@ -173,7 +173,7 @@ public final class CustomMapSerializer<T extends Map<?, ?>> extends MapSerialize @Override public Map onMapWrite(WriteContext writeContext, T value) { - writeContext.getBuffer().writeVarUint32Small7(value.size()); + writeContext.getBuffer().writeVarUInt32Small7(value.size()); return value; } @@ -185,7 +185,7 @@ public final class CustomMapSerializer<T extends Map<?, ?>> extends MapSerialize @Override public Map newMap(ReadContext readContext) { MemoryBuffer buffer = readContext.getBuffer(); - int numElements = buffer.readVarUint32Small7(); + int numElements = buffer.readVarUInt32Small7(); setNumElements(numElements); return new LinkedHashMap(numElements); } diff --git a/docs/guide/java/enum-configuration.md b/docs/guide/java/enum-configuration.md index c38507316..99a1bfce9 100644 --- a/docs/guide/java/enum-configuration.md +++ b/docs/guide/java/enum-configuration.md @@ -38,7 +38,7 @@ of numeric tag. ```java Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .serializeEnumByName(true) .build(); ``` diff --git a/docs/guide/java/field-configuration.md b/docs/guide/java/field-configuration.md index 6051090f6..48df5f040 100644 --- a/docs/guide/java/field-configuration.md +++ b/docs/guide/java/field-configuration.md @@ -264,14 +264,15 @@ Fory provides annotations to control integer encoding for cross-language compati ```java import org.apache.fory.annotation.Int32Type; +import org.apache.fory.config.Int32Encoding; public class MyStruct { // Variable-length encoding (default) - compact for small values - @Int32Type(compress = true) + @Int32Type(encoding = Int32Encoding.VARINT) private int compactId; // Fixed 4-byte encoding - consistent size - @Int32Type(compress = false) + @Int32Type(encoding = Int32Encoding.FIXED) private int fixedId; } ``` @@ -280,19 +281,19 @@ public class MyStruct { ```java import org.apache.fory.annotation.Int64Type; -import org.apache.fory.config.LongEncoding; +import org.apache.fory.config.Int64Encoding; public class MyStruct { // Variable-length encoding (default) - @Int64Type(encoding = LongEncoding.VARINT) + @Int64Type(encoding = Int64Encoding.VARINT) private long compactId; // Fixed 8-byte encoding - @Int64Type(encoding = LongEncoding.FIXED) + @Int64Type(encoding = Int64Encoding.FIXED) private long fixedTimestamp; // Tagged encoding (4 bytes for small values, 9 bytes otherwise) - @Int64Type(encoding = LongEncoding.TAGGED) + @Int64Type(encoding = Int64Encoding.TAGGED) private long taggedValue; } ``` @@ -300,37 +301,38 @@ public class MyStruct { ### Unsigned Integers ```java -import org.apache.fory.annotation.Uint8Type; -import org.apache.fory.annotation.Uint16Type; -import org.apache.fory.annotation.Uint32Type; -import org.apache.fory.annotation.Uint64Type; -import org.apache.fory.config.LongEncoding; +import org.apache.fory.annotation.UInt8Type; +import org.apache.fory.annotation.UInt16Type; +import org.apache.fory.annotation.UInt32Type; +import org.apache.fory.annotation.UInt64Type; +import org.apache.fory.config.Int32Encoding; +import org.apache.fory.config.Int64Encoding; public class UnsignedStruct { // Unsigned 8-bit [0, 255] - @Uint8Type - private short flags; + @UInt8Type + private int flags; // Unsigned 16-bit [0, 65535] - @Uint16Type + @UInt16Type private int port; // Unsigned 32-bit with varint encoding (default) - @Uint32Type(compress = true) + @UInt32Type(encoding = Int32Encoding.VARINT) private long compactCount; // Unsigned 32-bit with fixed encoding - @Uint32Type(compress = false) + @UInt32Type(encoding = Int32Encoding.FIXED) private long fixedCount; // Unsigned 64-bit with various encodings - @Uint64Type(encoding = LongEncoding.VARINT) + @UInt64Type(encoding = Int64Encoding.VARINT) private long varintU64; - @Uint64Type(encoding = LongEncoding.FIXED) + @UInt64Type(encoding = Int64Encoding.FIXED) private long fixedU64; - @Uint64Type(encoding = LongEncoding.TAGGED) + @UInt64Type(encoding = Int64Encoding.TAGGED) private long taggedU64; } ``` @@ -339,18 +341,18 @@ public class UnsignedStruct { | Annotation | Type ID | Encoding | Size | | -------------------------------- | ------- | -------- | ------------ | -| `@Int32Type(compress = true)` | 5 | varint | 1-5 bytes | -| `@Int32Type(compress = false)` | 4 | fixed | 4 bytes | +| `@Int32Type(encoding = VARINT)` | 5 | varint | 1-5 bytes | +| `@Int32Type(encoding = FIXED)` | 4 | fixed | 4 bytes | | `@Int64Type(encoding = VARINT)` | 7 | varint | 1-10 bytes | | `@Int64Type(encoding = FIXED)` | 6 | fixed | 8 bytes | | `@Int64Type(encoding = TAGGED)` | 8 | tagged | 4 or 9 bytes | -| `@Uint8Type` | 9 | fixed | 1 byte | -| `@Uint16Type` | 10 | fixed | 2 bytes | -| `@Uint32Type(compress = true)` | 12 | varint | 1-5 bytes | -| `@Uint32Type(compress = false)` | 11 | fixed | 4 bytes | -| `@Uint64Type(encoding = VARINT)` | 14 | varint | 1-10 bytes | -| `@Uint64Type(encoding = FIXED)` | 13 | fixed | 8 bytes | -| `@Uint64Type(encoding = TAGGED)` | 15 | tagged | 4 or 9 bytes | +| `@UInt8Type` | 9 | fixed | 1 byte | +| `@UInt16Type` | 10 | fixed | 2 bytes | +| `@UInt32Type(encoding = VARINT)` | 12 | varint | 1-5 bytes | +| `@UInt32Type(encoding = FIXED)` | 11 | fixed | 4 bytes | +| `@UInt64Type(encoding = VARINT)` | 14 | varint | 1-10 bytes | +| `@UInt64Type(encoding = FIXED)` | 13 | fixed | 8 bytes | +| `@UInt64Type(encoding = TAGGED)` | 15 | tagged | 4 or 9 bytes | **When to Use**: @@ -359,6 +361,45 @@ public class UnsignedStruct { - `tagged`: Good balance between size and performance - Unsigned types: For cross-language compatibility with Rust, Go, C++ +Unsigned Java scalar carriers are `int`/`Integer` for `@UInt8Type` and +`@UInt16Type`, and `long`/`Long` for `@UInt32Type` and `@UInt64Type`. +Annotating `byte` with `@UInt8Type` is invalid because Java `byte` cannot +represent the unsigned range. + +Integer annotations can also be applied to nested generic type arguments: + +```java +import java.util.List; +import java.util.Map; +import org.apache.fory.annotation.Int64Type; +import org.apache.fory.annotation.UInt32Type; +import org.apache.fory.config.Int32Encoding; +import org.apache.fory.config.Int64Encoding; + +public class NestedStruct { + private Map< + @UInt32Type(encoding = Int32Encoding.FIXED) Long, + List<@Int64Type(encoding = Int64Encoding.TAGGED) Long>> + values; +} +``` + +Specialized unsigned list carriers still use packed-array wire types when the +field or nested element encoding is fixed. If a `UInt32List` or `UInt64List` +field is annotated with a variable or tagged encoding, Fory serializes it with +the collection protocol so the element type metadata is preserved. + +Primitive unsigned arrays can use element annotations for packed-array metadata: + +```java +import org.apache.fory.annotation.UInt32Elements; + +public class IdBatch { + @UInt32Elements + private int[] ids; +} +``` + ## Complete Example ```java @@ -366,8 +407,8 @@ import org.apache.fory.Fory; import org.apache.fory.annotation.ForyField; import org.apache.fory.annotation.Ignore; import org.apache.fory.annotation.Int64Type; -import org.apache.fory.annotation.Uint64Type; -import org.apache.fory.config.LongEncoding; +import org.apache.fory.annotation.UInt64Type; +import org.apache.fory.config.Int64Encoding; import java.util.List; import java.util.Map; @@ -397,15 +438,15 @@ public class Document { // Integer with different encodings @ForyField(id = 6) - @Uint64Type(encoding = LongEncoding.VARINT) + @UInt64Type(encoding = Int64Encoding.VARINT) private long viewCount; // varint encoding @ForyField(id = 7) - @Uint64Type(encoding = LongEncoding.FIXED) + @UInt64Type(encoding = Int64Encoding.FIXED) private long fileSize; // fixed encoding @ForyField(id = 8) - @Uint64Type(encoding = LongEncoding.TAGGED) + @UInt64Type(encoding = Int64Encoding.TAGGED) private long checksum; // tagged encoding // Reference-tracked field for shared/circular references @@ -451,15 +492,15 @@ When serializing data to be read by other languages (Python, Rust, C++, Go), use public class CrossLangData { // Use field IDs for cross-language compatibility @ForyField(id = 0) - @Int32Type(compress = true) + @Int32Type(encoding = Int32Encoding.VARINT) private int intVar; @ForyField(id = 1) - @Uint64Type(encoding = LongEncoding.FIXED) + @UInt64Type(encoding = Int64Encoding.FIXED) private long longFixed; @ForyField(id = 2) - @Uint64Type(encoding = LongEncoding.TAGGED) + @UInt64Type(encoding = Int64Encoding.TAGGED) private long longTagged; @ForyField(id = 3, nullable = true) @@ -591,12 +632,12 @@ public class User { | `@ForyField(ref = true)` | Enable reference tracking | | `@ForyField(dynamic = ...)` | Control polymorphism for struct fields | | `@Ignore` | Exclude field from serialization | -| `@Int32Type(compress = ...)` | 32-bit signed integer encoding | +| `@Int32Type(encoding = ...)` | 32-bit signed integer encoding | | `@Int64Type(encoding = ...)` | 64-bit signed integer encoding | -| `@Uint8Type` | Unsigned 8-bit integer | -| `@Uint16Type` | Unsigned 16-bit integer | -| `@Uint32Type(compress = ...)` | Unsigned 32-bit integer encoding | -| `@Uint64Type(encoding = ...)` | Unsigned 64-bit integer encoding | +| `@UInt8Type` | Unsigned 8-bit integer | +| `@UInt16Type` | Unsigned 16-bit integer | +| `@UInt32Type(encoding = ...)` | Unsigned 32-bit integer encoding | +| `@UInt64Type(encoding = ...)` | Unsigned 64-bit integer encoding | ## Related Topics diff --git a/docs/guide/java/index.md b/docs/guide/java/index.md index baf60f741..a125059f3 100644 --- a/docs/guide/java/index.md +++ b/docs/guide/java/index.md @@ -67,7 +67,7 @@ public class Example { SomeClass object = new SomeClass(); // Note that Fory instances should be reused between // multiple serializations of different objects. - Fory fory = Fory.builder().withLanguage(Language.JAVA) + Fory fory = Fory.builder().withXlang(false) .requireClassRegistration(true) .build(); // Registering types can reduce class name serialization overhead, but not mandatory. @@ -90,7 +90,7 @@ public class Example { public static void main(String[] args) { SomeClass object = new SomeClass(); ThreadSafeFory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .buildThreadSafeFory(); fory.register(SomeClass.class, 1); byte[] bytes = fory.serialize(object); @@ -107,7 +107,7 @@ import org.apache.fory.config.*; public class Example { private static final ThreadSafeFory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .buildThreadSafeFory(); static { @@ -133,9 +133,9 @@ This is the default choice. It uses a fixed-size shared `ThreadPoolFory` sized t ```java ThreadSafeFory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .withRefTracking(false) - .withCompatibleMode(CompatibleMode.SCHEMA_CONSISTENT) + .withCompatible(false) .withAsyncCompilation(true) .buildThreadSafeFory(); ``` @@ -149,7 +149,7 @@ platform thread, or when you want to pin that choice regardless of JDK version: ```java ThreadSafeFory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .buildThreadLocalFory(); fory.register(SomeClass.class, 1); byte[] bytes = fory.serialize(object); @@ -165,9 +165,9 @@ pooled instance is already in use; the runtime does not key cached instances by ```java ThreadSafeFory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .withRefTracking(false) - .withCompatibleMode(CompatibleMode.SCHEMA_CONSISTENT) + .withCompatible(false) .withAsyncCompilation(true) .buildThreadSafeForyPool(poolSize); ``` @@ -177,23 +177,23 @@ ThreadSafeFory fory = Fory.builder() ```java // Single-thread Fory Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .withRefTracking(false) - .withCompatibleMode(CompatibleMode.SCHEMA_CONSISTENT) + .withCompatible(false) .withAsyncCompilation(true) .build(); // Thread-safe Fory (thread-safe Fory backed by a pool of Fory instances) ThreadSafeFory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .withRefTracking(false) - .withCompatibleMode(CompatibleMode.SCHEMA_CONSISTENT) + .withCompatible(false) .withAsyncCompilation(true) .buildThreadSafeFory(); // Explicit thread-local runtime ThreadSafeFory threadLocalFory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .buildThreadLocalFory(); ``` diff --git a/docs/guide/java/object-copy.md b/docs/guide/java/object-copy.md index 6a6d735ef..e31c1564d 100644 --- a/docs/guide/java/object-copy.md +++ b/docs/guide/java/object-copy.md @@ -53,12 +53,11 @@ handled correctly: ```java import org.apache.fory.Fory; -import org.apache.fory.config.Language; public class Example { public static void main(String[] args) { Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .withRefCopy(true) .build(); @@ -81,7 +80,6 @@ graph, and circular references can be copied correctly. ```java import org.apache.fory.Fory; -import org.apache.fory.config.Language; public class Example { static final class Address { @@ -95,7 +93,7 @@ public class Example { public static void main(String[] args) { Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .withRefCopy(true) .build(); @@ -119,7 +117,6 @@ cyclic references. This can be faster, but repeated references are copied into d ```java import org.apache.fory.Fory; -import org.apache.fory.config.Language; public class Example { static final class Address { @@ -133,7 +130,7 @@ public class Example { public static void main(String[] args) { Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .withRefCopy(false) .build(); @@ -213,12 +210,11 @@ For general multi-threaded usage: ```java import org.apache.fory.Fory; import org.apache.fory.ThreadSafeFory; -import org.apache.fory.config.Language; public class Example { public static void main(String[] args) { ThreadSafeFory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .withRefCopy(true) .buildThreadSafeFory(); diff --git a/docs/guide/java/schema-evolution.md b/docs/guide/java/schema-evolution.md index acd870f55..8ae9b8ccc 100644 --- a/docs/guide/java/schema-evolution.md +++ b/docs/guide/java/schema-evolution.md @@ -25,19 +25,19 @@ This page covers schema evolution, meta sharing, and handling non-existent/unkno In many systems, the schema of a class used for serialization may change over time. For instance, fields within a class may be added or removed. When serialization and deserialization processes use different versions of jars, the schema of the class being deserialized may differ from the one used during serialization. -### Default Mode: SCHEMA_CONSISTENT +### Default Mode: Schema Consistent -By default, Fory serializes objects using the `CompatibleMode.SCHEMA_CONSISTENT` mode. This mode assumes that the deserialization process uses the same class schema as the serialization process, minimizing payload overhead. However, if there is a schema inconsistency, deserialization will fail. +By default, Fory serializes objects using schema-consistent mode. This mode assumes that the deserialization process uses the same class schema as the serialization process, minimizing payload overhead. However, if there is a schema inconsistency, deserialization will fail. ### Compatible Mode -If the schema is expected to change, to make deserialization succeed (i.e., schema forward/backward compatibility), users must configure Fory to use `CompatibleMode.COMPATIBLE`. This can be done using the `ForyBuilder#withCompatibleMode(CompatibleMode.COMPATIBLE)` method. +If the schema is expected to change, to make deserialization succeed (i.e., schema forward/backward compatibility), users must configure Fory with `ForyBuilder#withCompatible(true)`. In this compatible mode, deserialization can handle schema changes such as missing or extra fields, allowing it to succeed even when the serialization and deserialization processes have different class schemas. ```java Fory fory = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE) + .withCompatible(true) .build(); byte[] bytes = fory.serialize(object); @@ -48,12 +48,12 @@ This compatible mode involves serializing class metadata into the serialized out ### Disable Evolution for Stable Classes -If a class schema is stable and will not change, you can opt out of schema evolution on a per-class basis to avoid compatible metadata overhead. Annotate the class with `@ForyObject(evolving = false)` to force `STRUCT/NAMED_STRUCT` type IDs even when Compatible mode is enabled. +If a class schema is stable and will not change, you can opt out of schema evolution on a per-class basis to avoid compatible metadata overhead. Annotate the class with `@ForyStruct(evolving = false)` to force `STRUCT/NAMED_STRUCT` type IDs even when Compatible mode is enabled. ```java -import org.apache.fory.annotation.ForyObject; +import org.apache.fory.annotation.ForyStruct; -@ForyObject(evolving = false) +@ForyStruct(evolving = false) public class StableMessage { public int id; public String name; @@ -70,7 +70,7 @@ Fory supports sharing type metadata (class name, field name, final field type in ```java // Fory.builder() -// .withLanguage(Language.JAVA) +// .withXlang(false) // .withRefTracking(false) // // share meta across serialization. // .withMetaShare(true) @@ -152,9 +152,9 @@ public class StructMappingExample { } static ThreadSafeFory fory1 = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE).buildThreadSafeFory(); + .withCompatible(true).buildThreadSafeFory(); static ThreadSafeFory fory2 = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE).buildThreadSafeFory(); + .withCompatible(true).buildThreadSafeFory(); static { fory1.register(Struct1.class); @@ -175,7 +175,7 @@ public class StructMappingExample { ## Deserialize POJO into Another Type -Fory allows you to serialize one POJO and deserialize it into a different POJO. The different POJO means schema inconsistency. Users must configure Fory with `CompatibleMode` set to `org.apache.fory.config.CompatibleMode.COMPATIBLE`. +Fory allows you to serialize one POJO and deserialize it into a different POJO. The different POJO means schema inconsistency. Users must enable compatible mode with `ForyBuilder#withCompatible(true)`. ```java public class DeserializeIntoType { @@ -196,7 +196,7 @@ public class DeserializeIntoType { } static ThreadSafeFory fory = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE).buildThreadSafeFory(); + .withCompatible(true).buildThreadSafeFory(); public static void main(String[] args) { Struct1 struct1 = new Struct1(10, "abc"); diff --git a/docs/guide/java/troubleshooting.md b/docs/guide/java/troubleshooting.md index c03c19a1a..d46d66c5b 100644 --- a/docs/guide/java/troubleshooting.md +++ b/docs/guide/java/troubleshooting.md @@ -23,25 +23,25 @@ This page covers common issues and their solutions. ## Class Inconsistency and Class Version Check -If you create Fory without setting `CompatibleMode` to `org.apache.fory.config.CompatibleMode.COMPATIBLE`, and you get a strange serialization error, it may be caused by class inconsistency between the serialization peer and deserialization peer. +If you create Fory without enabling compatible mode and you get a strange serialization error, it may be caused by class inconsistency between the serialization peer and deserialization peer. -In such cases, you can invoke `ForyBuilder#withClassVersionCheck` to create Fory to validate it. If deserialization throws `org.apache.fory.exception.ClassNotCompatibleException`, it shows classes are inconsistent, and you should create Fory with `ForyBuilder#withCompatibleMode(CompatibleMode.COMPATIBLE)`. +In such cases, you can invoke `ForyBuilder#withClassVersionCheck` to create Fory to validate it. If deserialization throws `org.apache.fory.exception.ClassNotCompatibleException`, it shows classes are inconsistent, and you should create Fory with `ForyBuilder#withCompatible(true)`. ```java // Enable class version check to diagnose issues Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .withClassVersionCheck(true) .build(); // If ClassNotCompatibleException is thrown, use compatible mode Fory fory = Fory.builder() - .withLanguage(Language.JAVA) - .withCompatibleMode(CompatibleMode.COMPATIBLE) + .withXlang(false) + .withCompatible(true) .build(); ``` -**Note**: `CompatibleMode.COMPATIBLE` has more performance and space cost. Do not set it by default if your classes are always consistent between serialization and deserialization. +**Note**: compatible mode has more performance and space cost. Do not set it by default if your classes are always consistent between serialization and deserialization. ## Using Wrong API for Deserialization @@ -71,7 +71,7 @@ MyClass typedResult = fory.deserialize(typedBytes, MyClass.class); ## Deserialize POJO into Another Type -If you want to serialize one POJO and deserialize it into a different POJO type, you must use `CompatibleMode.COMPATIBLE`: +If you want to serialize one POJO and deserialize it into a different POJO type, enable compatible mode: ```java public class DeserializeIntoType { @@ -92,7 +92,7 @@ public class DeserializeIntoType { } static ThreadSafeFory fory = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE).buildThreadSafeFory(); + .withCompatible(true).buildThreadSafeFory(); public static void main(String[] args) { Struct1 struct1 = new Struct1(10, "abc"); @@ -124,7 +124,7 @@ fory.register(MyClass.class, 100); ```java Fory fory = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE) + .withCompatible(true) .build(); ``` diff --git a/docs/guide/java/type-registration.md b/docs/guide/java/type-registration.md index 2e63a35e1..66daf8aa1 100644 --- a/docs/guide/java/type-registration.md +++ b/docs/guide/java/type-registration.md @@ -97,7 +97,7 @@ If max depth is reached, Fory will throw `ForyException`. This can be used to pr ```java Fory fory = Fory.builder() - .withLanguage(Language.JAVA) + .withXlang(false) .withMaxDepth(100) // Set custom max depth .build(); ``` diff --git a/docs/guide/javascript/troubleshooting.md b/docs/guide/javascript/troubleshooting.md index 275780d7b..aa77c7fe8 100644 --- a/docs/guide/javascript/troubleshooting.md +++ b/docs/guide/javascript/troubleshooting.md @@ -25,7 +25,7 @@ This page covers common problems when using Fory JavaScript. The Fory JavaScript runtime only reads Fory cross-language payloads. If the producer is a Java or Go service using a language-native format, the JavaScript side cannot decode it. -Fix: switch the producer to the cross-language mode. For Java, use `.withLanguage(Language.XLANG)`; for Go, use `WithXlang(true)`. +Fix: switch the producer to the cross-language mode. For Java, use `.withXlang(true)`; for Go, use `WithXlang(true)`. ## `maxDepth must be an integer >= 2` diff --git a/docs/guide/kotlin/default-values.md b/docs/guide/kotlin/default-values.md index cba994383..e706e8656 100644 --- a/docs/guide/kotlin/default-values.md +++ b/docs/guide/kotlin/default-values.md @@ -33,7 +33,7 @@ When a Kotlin data class has parameters with default values, Fory can: This feature is automatically enabled when: -- Compatible mode is enabled (`withCompatibleMode(CompatibleMode.COMPATIBLE)`) +- Compatible mode is enabled (`withCompatible(true)`) - Kotlin serializers are registered (`KotlinSerializers.registerSerializers(fory)`) - A field is missing from the serialized data but exists in the target class with a default value @@ -41,7 +41,6 @@ This feature is automatically enabled when: ```kotlin import org.apache.fory.Fory -import org.apache.fory.config.CompatibleMode import org.apache.fory.serializer.kotlin.KotlinSerializers // Original data class @@ -52,7 +51,7 @@ data class UserV2(val name: String, val age: Int, val email: String = "default@e fun main() { val fory = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE) + .withCompatible(true) .build() KotlinSerializers.registerSerializers(fory) fory.register(User::class.java) @@ -94,7 +93,7 @@ data class ConfigV2( ) val fory = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE) + .withCompatible(true) .build() KotlinSerializers.registerSerializers(fory) diff --git a/docs/guide/kotlin/fory-creation.md b/docs/guide/kotlin/fory-creation.md index bb82ac872..0ccb21c14 100644 --- a/docs/guide/kotlin/fory-creation.md +++ b/docs/guide/kotlin/fory-creation.md @@ -93,14 +93,13 @@ Common options for Kotlin: ```kotlin import org.apache.fory.Fory -import org.apache.fory.config.CompatibleMode import org.apache.fory.serializer.kotlin.KotlinSerializers val fory = Fory.builder() // Enable reference tracking for circular references .withRefTracking(true) // Enable schema evolution support - .withCompatibleMode(CompatibleMode.COMPATIBLE) + .withCompatible(true) // Enable async compilation for better startup performance .withAsyncCompilation(true) // Compression options diff --git a/docs/guide/python/cross-language.md b/docs/guide/python/cross-language.md index 61f6d1dab..306453836 100644 --- a/docs/guide/python/cross-language.md +++ b/docs/guide/python/cross-language.md @@ -65,7 +65,7 @@ public class Person { } Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .withRefTracking(true) .build(); diff --git a/docs/guide/rust/cross-language.md b/docs/guide/rust/cross-language.md index 3c80e2c9e..f5f0d24b1 100644 --- a/docs/guide/rust/cross-language.md +++ b/docs/guide/rust/cross-language.md @@ -101,7 +101,7 @@ public class Person { } Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .withRefTracking(true) .build(); diff --git a/docs/guide/rust/field-configuration.md b/docs/guide/rust/field-configuration.md index ac2a29762..eb7027b1c 100644 --- a/docs/guide/rust/field-configuration.md +++ b/docs/guide/rust/field-configuration.md @@ -321,10 +321,10 @@ struct Bad2 { field: String, } -// Error: removed shorthand +// Error: invalid encoding for i32 #[derive(ForyStruct)] struct Bad3 { - #[fory(compress = false)] // Compile error: use encoding = fixed + #[fory(encoding = tagged)] // Compile error: tagged is only valid for i64/u64 field: i32, } ``` diff --git a/docs/guide/scala/default-values.md b/docs/guide/scala/default-values.md index 92e62e1b0..7245e92e9 100644 --- a/docs/guide/scala/default-values.md +++ b/docs/guide/scala/default-values.md @@ -49,7 +49,7 @@ Fory supports default values for: This feature is automatically enabled when: -- Compatible mode is enabled (`withCompatibleMode(CompatibleMode.COMPATIBLE)`) +- Compatible mode is enabled (`withCompatible(true)`) - The target class is detected as a Scala class with default values - A field is missing from the serialized data but exists in the target class @@ -61,7 +61,6 @@ No additional configuration is required. ```scala import org.apache.fory.Fory -import org.apache.fory.config.CompatibleMode import org.apache.fory.serializer.scala.ScalaSerializers // Class WITHOUT default values (for serialization) @@ -71,7 +70,7 @@ case class PersonV1(name: String) case class PersonV2(name: String, age: Int = 25, city: String = "Unknown") val fory = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE) + .withCompatible(true) .withScalaOptimizationEnabled(true) .build() @@ -103,7 +102,7 @@ class EmployeeV2( ) val fory = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE) + .withCompatible(true) .withScalaOptimizationEnabled(true) .build() @@ -137,7 +136,7 @@ case class ConfigV2( ) val fory = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE) + .withCompatible(true) .withScalaOptimizationEnabled(true) .build() @@ -166,7 +165,7 @@ object Models { } val fory = Fory.builder() - .withCompatibleMode(CompatibleMode.COMPATIBLE) + .withCompatible(true) .withScalaOptimizationEnabled(true) .build() diff --git a/docs/guide/scala/fory-creation.md b/docs/guide/scala/fory-creation.md index fecfd0224..b79e61856 100644 --- a/docs/guide/scala/fory-creation.md +++ b/docs/guide/scala/fory-creation.md @@ -119,7 +119,6 @@ Common options for Scala: ```scala import org.apache.fory.Fory -import org.apache.fory.config.CompatibleMode import org.apache.fory.serializer.scala.ScalaSerializers val fory = Fory.builder() @@ -127,7 +126,7 @@ val fory = Fory.builder() // Enable reference tracking for circular references .withRefTracking(true) // Enable schema evolution support - .withCompatibleMode(CompatibleMode.COMPATIBLE) + .withCompatible(true) // Enable async compilation for better startup performance .withAsyncCompilation(true) .build() diff --git a/docs/guide/xlang/field-nullability.md b/docs/guide/xlang/field-nullability.md index 516039f3f..ab888a563 100644 --- a/docs/guide/xlang/field-nullability.md +++ b/docs/guide/xlang/field-nullability.md @@ -107,7 +107,7 @@ public class Person { } Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .build(); fory.register(Person.class, "example.Person"); ``` diff --git a/docs/guide/xlang/field-reference-tracking.md b/docs/guide/xlang/field-reference-tracking.md index 6b5b28698..1ed94bd3d 100644 --- a/docs/guide/xlang/field-reference-tracking.md +++ b/docs/guide/xlang/field-reference-tracking.md @@ -35,7 +35,7 @@ Reference tracking enables: ```java Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .withRefTracking(true) .build(); ``` @@ -103,7 +103,7 @@ Key behavior: ```java // Reference tracking enabled, but non-nullable fields still skip ref flags Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .withRefTracking(true) .build(); ``` diff --git a/docs/guide/xlang/getting-started.md b/docs/guide/xlang/getting-started.md index 9ebb01f6c..6cd8ca3a4 100644 --- a/docs/guide/xlang/getting-started.md +++ b/docs/guide/xlang/getting-started.md @@ -81,7 +81,7 @@ import org.apache.fory.*; import org.apache.fory.config.*; Fory fory = Fory.builder() - .withLanguage(Language.XLANG) // Enable cross-language mode + .withXlang(true) // Enable cross-language mode .withRefTracking(true) // Optional: for circular references .build(); ``` @@ -246,7 +246,7 @@ public class Person { public class HelloWorld { public static void main(String[] args) throws Exception { Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .build(); fory.register(Person.class, "example.Person"); diff --git a/docs/guide/xlang/index.md b/docs/guide/xlang/index.md index 44a9f3df3..4d322a0ac 100644 --- a/docs/guide/xlang/index.md +++ b/docs/guide/xlang/index.md @@ -69,7 +69,7 @@ public class Person { } Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .build(); fory.register(Person.class, "example.Person"); diff --git a/docs/guide/xlang/serialization.md b/docs/guide/xlang/serialization.md index 1257307db..dda0fc696 100644 --- a/docs/guide/xlang/serialization.md +++ b/docs/guide/xlang/serialization.md @@ -42,7 +42,7 @@ import java.util.*; public class Example1 { public static void main(String[] args) { - Fory fory = Fory.builder().withLanguage(Language.XLANG).build(); + Fory fory = Fory.builder().withXlang(true).build(); List<Object> list = ofArrayList(true, false, "str", -1.1, 1, new int[100], new double[20]); byte[] bytes = fory.serialize(list); // bytes can be deserialized by other languages @@ -201,7 +201,7 @@ public class Example2 { // mvn exec:java -Dexec.mainClass="org.apache.fory.examples.Example2" public static void main(String[] args) { - Fory fory = Fory.builder().withLanguage(Language.XLANG).build(); + Fory fory = Fory.builder().withXlang(true).build(); fory.register(SomeClass1.class, "example.SomeClass1"); fory.register(SomeClass2.class, "example.SomeClass2"); byte[] bytes = fory.serialize(createObject()); @@ -447,7 +447,7 @@ public class ReferenceExample { // mvn exec:java -Dexec.mainClass="org.apache.fory.examples.ReferenceExample" public static void main(String[] args) { - Fory fory = Fory.builder().withLanguage(Language.XLANG) + Fory fory = Fory.builder().withXlang(true) .withRefTracking(true).build(); fory.register(SomeClass.class, "example.SomeClass"); byte[] bytes = fory.serialize(createObject()); diff --git a/docs/guide/xlang/troubleshooting.md b/docs/guide/xlang/troubleshooting.md index 09def125b..2ccb2071f 100644 --- a/docs/guide/xlang/troubleshooting.md +++ b/docs/guide/xlang/troubleshooting.md @@ -180,7 +180,7 @@ StackOverflowError or RecursionError ```java // Java Fory fory = Fory.builder() - .withLanguage(Language.XLANG) + .withXlang(true) .withRefTracking(true) .build(); ``` @@ -290,7 +290,7 @@ python deserializer.py data.bin 1. **Not registering types**: Always register custom types before use 2. **Inconsistent type names/IDs**: Use the same names/IDs across all languages -3. **Forgetting xlang mode**: Use `Language.XLANG` in Java +3. **Forgetting xlang mode**: Use `.withXlang(true)` in Java 4. **Wrong type annotations**: Use `pyfory.Int32Type` etc. in Python 5. **Ignoring reference tracking**: Enable for circular/shared references diff --git a/docs/guide/xlang/zero-copy.md b/docs/guide/xlang/zero-copy.md index e1ad25fa2..6d7ceba04 100644 --- a/docs/guide/xlang/zero-copy.md +++ b/docs/guide/xlang/zero-copy.md @@ -51,7 +51,7 @@ import java.util.stream.Collectors; public class ZeroCopyExample { public static void main(String[] args) { - Fory fory = Fory.builder().withLanguage(Language.XLANG).build(); + Fory fory = Fory.builder().withXlang(true).build(); // Data with large arrays List<Object> list = List.of( --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
