Configuration
This page documents all configuration options available through ForyBuilder.
ForyBuilder Options
Example Configuration
Fory fory = Fory.builder()
.withXlang(false)
// 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)
// Optional: use `compatible=false` only when
// every reader and writer always uses the same class schema.
// .withCompatible(false)
// enable async multi-threaded compilation.
.withAsyncCompilation(true)
.build();
Compatible Mode
Compatible mode is enabled by default for both xlang and native mode. Keep this default when classes may evolve independently, when services deploy separately, or when xlang schemas are written by hand in different languages.
Use withCompatible(false) only when the class schema used to deserialize every payload is always
the same as the class schema used to serialize it and you want faster serialization and smaller size.
For xlang payloads, call withCompatible(false) only after verifying that every language uses the same schema, or when native types are generated from Fory schema IDL.
Security
Keep class registration enabled for production and any untrusted payload source:
Fory fory = Fory.builder()
.requireClassRegistration(true)
.withMaxDepth(50)
.build();
Security-related options:
requireClassRegistration(true)restricts deserialization to registered classes.withMaxDepth(...)rejects unexpectedly deep object graphs.withMaxTypeFields(...)andwithMaxTypeMetaBytes(...)bound the field count and encoded body size of one received remote metadata body.withMaxSchemaVersionsPerType(...)andwithMaxAverageSchemaVersionsPerType(...)bound accepted remote metadata versions without changing registration, dynamic loading, or schema-evolution semantics.withDeserializeUnknownClass(false)avoids materializing unknown classes from metadata.checkJdkClassSerializable(true)keeps the JDK serializability check forjava.*classes.- Class registration warnings can be useful during security audits; use
suppressClassRegistrationWarnings(false)when you need to surface unexpected types.
Use requireClassRegistration(false) only for trusted payloads, and pair it with a TypeChecker
allow list when dynamic class loading is required.
Related Topics
- Schema Metadata -
@ForyField,@Ignore, integer encoding annotations,serializeEnumByName, and@ForyEnumId - Schema Evolution - Compatible mode and meta sharing
- Compression - Int, long, and array compression details
- Type Registration - Class registration options
- Static Generated Serializers - Annotation-processor static generated serializers for
@ForyStruct,codegen=false, and Android
