Configuration Options
This page documents all configuration options available through ForyBuilder.
ForyBuilder Options
| Option Name | Description | Default Value |
|---|---|---|
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, true)). Note that enabling ref tracking should happen before serializer codegen of any types which contain time fields. Otherwise, those fields will still skip ref tracking. | true |
compressInt | Enables or disables int compression for smaller size. | true |
compressLong | Enables or disables long compression for smaller size. | true |
compressIntArray | Enables or disables SIMD-accelerated compression for int arrays when values can fit in smaller data types. Requires Java 16+. | true |
compressLongArray | Enables or disables SIMD-accelerated compression for long arrays when values can fit in smaller data types. Requires Java 16+. | true |
compressString | Enables or disables string compression for smaller size. | false |
classLoader | The classloader should not be updated; Fory caches class metadata. Use LoaderBinding or ThreadSafeFory for classloader updates. | Thread.currentThread().getContextClassLoader() |
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. | CompatibleMode.SCHEMA_CONSISTENT |
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. | false |
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. | true |
registerGuavaTypes | Whether to pre-register Guava types such as RegularImmutableMap/RegularImmutableList. These types are not public API, but seem pretty stable. | true |
requireClassRegistration | Disabling may allow unknown classes to be deserialized, potentially causing security risks. | true |
maxDepth | Set max depth for deserialization, when depth exceeds, an exception will be thrown. This can be used to refuse deserialization DDOS attack. | 50 |
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. | true |
metaShareEnabled | Enables or disables meta share mode. | true if CompatibleMode.Compatible is set, otherwise false. |
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. | true if CompatibleMode.Compatible is set, otherwise false. |
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. | DeflaterMetaCompressor |
deserializeNonexistentClass | Enables or disables deserialization/skipping of data for non-existent classes. | true if CompatibleMode.Compatible is set, otherwise false. |
codeGenEnabled | Disabling may result in faster initial serialization but slower subsequent serializations. | true |
asyncCompilationEnabled | If enabled, serialization uses interpreter mode first and switches to JIT serialization after async serializer JIT for a class is finished. | false |
scalaOptimizationEnabled | Enables or disables Scala-specific serialization optimization. | false |
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. | true |
serializeEnumByName | When Enabled, fory serialize enum by name instead of ordinal. | false |
Example Configuration
Fory fory = Fory.builder()
.withLanguage(Language.JAVA)
// enable reference tracking for shared/circular reference.
// Disable it will have better performance if no duplicate reference.
.withRefTracking(false)
// compress int for smaller size
.withIntCompressed(true)
// compress long for smaller size
.withLongCompressed(true)
.withCompatibleMode(CompatibleMode.SCHEMA_CONSISTENT)
// enable type forward/backward compatibility
// disable it for small size and better performance.
// .withCompatibleMode(CompatibleMode.COMPATIBLE)
// enable async multi-threaded compilation.
.withAsyncCompilation(true)
.build();
Related Topics
- Schema Evolution - Compatible mode and meta sharing
- Compression - Int, long, and array compression details
- Type Registration - Class registration options