Thanks to visit codestin.com
Credit goes to fory.apache.org

Skip to main content
Version: 0.14

Configuration Options

This page documents all configuration options available through ForyBuilder.

ForyBuilder Options

Option NameDescriptionDefault Value
timeRefIgnoredWhether 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
compressIntEnables or disables int compression for smaller size.true
compressLongEnables or disables long compression for smaller size.true
compressIntArrayEnables or disables SIMD-accelerated compression for int arrays when values can fit in smaller data types. Requires Java 16+.true
compressLongArrayEnables or disables SIMD-accelerated compression for long arrays when values can fit in smaller data types. Requires Java 16+.true
compressStringEnables or disables string compression for smaller size.false
classLoaderThe classloader should not be updated; Fory caches class metadata. Use LoaderBinding or ThreadSafeFory for classloader updates.Thread.currentThread().getContextClassLoader()
compatibleModeType 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
checkClassVersionDetermines 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
checkJdkClassSerializableEnables or disables checking of Serializable interface for classes under java.*. If a class under java.* is not Serializable, Fory will throw an UnsupportedOperationException.true
registerGuavaTypesWhether to pre-register Guava types such as RegularImmutableMap/RegularImmutableList. These types are not public API, but seem pretty stable.true
requireClassRegistrationDisabling may allow unknown classes to be deserialized, potentially causing security risks.true
maxDepthSet max depth for deserialization, when depth exceeds, an exception will be thrown. This can be used to refuse deserialization DDOS attack.50
suppressClassRegistrationWarningsWhether 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
metaShareEnabledEnables or disables meta share mode.true if CompatibleMode.Compatible is set, otherwise false.
scopedMetaShareEnabledScoped 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.
metaCompressorSet 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
deserializeNonexistentClassEnables or disables deserialization/skipping of data for non-existent classes.true if CompatibleMode.Compatible is set, otherwise false.
codeGenEnabledDisabling may result in faster initial serialization but slower subsequent serializations.true
asyncCompilationEnabledIf enabled, serialization uses interpreter mode first and switches to JIT serialization after async serializer JIT for a class is finished.false
scalaOptimizationEnabledEnables or disables Scala-specific serialization optimization.false
copyRefWhen 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
serializeEnumByNameWhen 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();