JDK25+ 需加 --add-opens=java.base/java.lang.invoke=ALL-UNNAMED,否则回退 Unsafe 或不可用;Python row 格式需额外安装 pyfory[format];C++ 用 MSVC 构建需开启 /Zc:preprocessor

fory
apacheApache-2.0活跃维护极快的多语言序列化框架,支持领域对象、Schema IDL 和跨语言数据交换,适合需要高性能编解码与跨语言通信的场景。
A blazingly fast multi-language serialization framework for idiomatic domain objects, schema IDL, and cross-language data exchange.
pip install pyfory
# 或 Java Maven: org.apache.fory:fory-core:1.7.7README 未说明
Apache Fory 是跨语言高性能序列化框架,直接序列化各语言原生对象并支持跨语言数据交换
极快的多语言序列化框架,支持领域对象、Schema IDL 和跨语言数据交换,适合需要高性能编解码与跨语言通信的场景。
核心能力
- 直接序列化 Java 类、Python dataclass、Go/Rust/C++ struct 等原生对象
- 紧凑二进制编码支持 schema 演进、多态类型与共享/循环引用
- 用带引用的 Schema IDL 一次定义并生成各语言原生模型
- Java 提供 JIT 序列化器,其他语言用生成/静态序列化器优化热路径
- Row 格式支持零拷贝随机字段访问与部分读取
容易踩的坑
- v1.7.7最新正式版2026-10-12 · 2026-10-12 08:04 UTC
Highlights
- Configure read-side JSON null handling globally or per property, including null collection elements and map values.
- Improve JSON codec generation and string writing, and reduce C++ serialization overhead.
- Fix JSON object field semantics, compatible field-type validation, and schema compiler output across languages.
- Publish reproducible Java and Kotlin release archives with improved license and notice packaging.
Features
- perf(cpp): avoid duplicate TypeInfo lookup in compatible reads by @BrianLii in https://github.com/apache/fory/pull/4085
- feat(json): add read-side null handling by @chaokunyang in https://github.com/apache/fory/pull/4095
- perf(java): eliminate JSON codec sizing trial compilations by @chaokunyang in https://github.com/apache/fory/pull/4096
- perf(java): reduce codegen cost by @chaokunyang in https://github.com/apache/fory/pull/4097
- perf(java): skip runtime NON_EMPTY checks for final JSON property types by @pavel-ptashyts in https://github.com/apache/fory/pull/4111
- perf(cpp): serialize forward_list without a temporary vector by @BrianLii in https://github.com/apache/fory/pull/4113
- perf(java): copy plain runs after the first escape when writing JSON strings by @pavel-ptashyts in https://github.com/apache/fory/pull/4122
Bug Fix
- fix(integration): resolve Go generated package for Dependabot by @chaokunyang in https://github.com/apache/fory/pull/4086
- ci: Bump google.golang.org/grpc from 1.83.1 to 1.83.2 in /integration_tests/grpc_tests/go by @dependabot[bot] in https://github.com/apache/fory/pull/4087
- fix(java): keep JSON string writer prefix field names unique past 160 properties by @pavel-ptashyts in https://github.com/apache/fory/pull/4099
- fix(javascript): improve hps string writing by @pjfanning in https://github.com/apache/fory/pull/4098
- ci: Bump brace-expansion from 1.1.18 to 1.1.21 in /javascript by @dependabot[bot] in https://github.com/apache/fory/pull/4104
- ci: Bump com.fasterxml.jackson.core:jackson-databind from 2.22.2 to 2.22.3 in /benchmarks/java by @dependabot[bot] in https://github.com/apache/fory/pull/4110
- fix(compiler): include null in TS map value types for optional map values by @ayush00git in https://github.com/apache/fory/pull/4108
- fix(compiler): escape Python field names that shadow generated default helpers by @ayush00git in https://github.com/apache/fory/pull/4107
- fix(compiler): fix Java, Kotlin and Scala codegen emission bugs by @ayush00git in https://github.com/apache/fory/pull/4109
- ci: Bump com.fasterxml.jackson.core:jackson-core from 2.18.8 to 2.18.11 in /java/fory-test-core by @dependabot[bot] in https://github.com/apache/fory/pull/4115
- ci: Bump com.fasterxml.jackson.core:jackson-core from 2.18.8 to 2.18.11 in /java/fory-testsuite by @dependabot[bot] in https://github.com/apache/fory/pull/4120
- fix(compiler): preserve union case names on unknown-carrier collisions by @ayush00git in https://github.com/apache/fory/pull/4106
- fix(license): list zmij in fory-json jar LICENSE; per-module Scala NOTICE by @pjfanning in https://github.com/apache/fory/pull/4130
- fix(license): add missing third-party attributions and ship LICENSE/NOTICE in Python wheels by @pjfanning in https://github.com/apache/fory/pull/4127
- ci: check license headers in swift, dart, cython, idl, bazel, sbt and msbuild files by @pjfanning in https://github.com/apache/fory/pull/4125
- fix(java): advance readerIndex in continueReadBinarySize by @Hkwaynewing in https://github.com/apache/fory/pull/4133
- fix(release): archive RC tags without temporary license commits by @chaokunyang in https://github.com/apache/fory/pull/4134
- fix(java): preserve JSON object field semantics by @chaokunyang in https://github.com/apache/fory/pull/4142
- fix(java): make Java and Kotlin release archives reproducible by @chaokunyang in https://github.com/apache/fory/pull/4143
- fix(java): validate compatible values against local field types by @chaokunyang
- v1.7.62026-09-30 · 2026-09-30 02:03 UTC
查看更新说明
Highlights
- JSON can reject missing required constructor properties with
ForyJson.builder().failOnMissingRequiredProperties(true). This opt-in setting supports Java records and property-based creators, Scala case classes, and Kotlin constructor models while preserving declared defaults. - JSON
NON_DEFAULTinclusion now retains properties without defaults instead of rejecting them, including required constructor properties in Java, Scala, and Kotlin.
Features
- feat(json): configure missing required constructor properties by @chaokunyang in https://github.com/apache/fory/pull/4079
Bug Fix
- fix(json): retain properties without defaults under NON_DEFAULT by @chaokunyang in https://github.com/apache/fory/pull/4078
Full Changelog: https://github.com/apache/fory/compare/v1.7.5...v1.7.6
- JSON can reject missing required constructor properties with
- v1.7.52026-09-25 · 2026-09-25 03:04 UTC
查看更新说明
Highlights
- JSON output now supports per-call pretty printing, non-ASCII escaping, configurable byte-array formats including Base16, and explicit default-value omission.
- Scala and Kotlin JSON handling improves codec coverage and missing-field defaults, with additional GraalVM fixes for Java JSON accessors.
- Python adds collection-subclass support and fixes named-tuple and temporal-array-buffer handling.
Features
- perf(java): copy plain runs between escapes when decoding json strings by @pavel-ptashyts in https://github.com/apache/fory/pull/4058
- perf(java): share JSON reader and writer byte buffers by @chaokunyang in https://github.com/apache/fory/pull/4061
- feat(python): support collection subclass by @chaokunyang in https://github.com/apache/fory/pull/4063
- feat(java): improve json type support by @chaokunyang in https://github.com/apache/fory/pull/4064
- test(scala): cover documented fory-json-scala types and error paths by @pjfanning in https://github.com/apache/fory/pull/4070
- feat(json): add per-call pretty output for strings and bytes by @chaokunyang in https://github.com/apache/fory/pull/4073
- feat(json): add explicit default omission and Scala empty inclusion by @chaokunyang in https://github.com/apache/fory/pull/4074
- feat(json): add global byte array formats and Base16 support by @chaokunyang in https://github.com/apache/fory/pull/4075
- feat(json): support non-ASCII escaping by @chaokunyang in https://github.com/apache/fory/pull/4077
Bug Fix
- fix(java): guard LambdaGetterJsonAccessor and LambdaSetterJsonAccessor with GraalvmSupport.isGraalBuildTime() by @zhfeng in https://github.com/apache/fory/pull/4060
- fix(python): support named tuples and temporal array buffers by @chaokunyang in https://github.com/apache/fory/pull/4062
- fix(java): cache JSON method lambda visibility checks by @chaokunyang in https://github.com/apache/fory/pull/4071
- fix(json): correct Scala codecs and Scala/Kotlin missing-field defaults by @chaokunyang in https://github.com/apache/fory/pull/4072
- fix: decode remote schemas without caching after quota exhaustion by @chaokunyang in https://github.com/apache/fory/pull/4076
Other Improvements
- docs: update release version to 1.7.4 by @chaokunyang in https://github.com/apache/fory/pull/4065
New Contributors
- @pavel-ptashyts made their first contribution in https://github.com/apache/fory/pull/4058
Full Changelog: https://github.com/apache/fory/compare/v1.7.4...v1.7.5
- v1.7.42026-09-20 · 2026-09-20 14:32 UTC
查看更新说明
Highlights
- Improve Java JSON read/write performance and Scala collection codecs.
- Support runtime Kotlin
KTypetokens for JSON framework integrations. - Preserve declared registered field types during compatible Java deserialization and validate non-nullable field values before serialization.
Features
- perf(java): optimize json write/read perf by @chaokunyang in https://github.com/apache/fory/pull/4044
- perf(java): optimize json write/read perf by @chaokunyang in https://github.com/apache/fory/pull/4045
- feat(kotlin): support runtime Kotlin JSON type tokens by @chaokunyang in https://github.com/apache/fory/pull/4054
Bug Fix
- fix(license): restore dataclasses and gRPC attributions by @chaokunyang in https://github.com/apache/fory/pull/4046
- fix(java): preserve compatible registered field type by @aditya0za005-ux in https://github.com/apache/fory/pull/4048
- fix(java): avoid JDK 8 ARM Unsafe address miscompilation by @chaokunyang in https://github.com/apache/fory/pull/4049
- fix(java): check non-nullable field values before serialization by @chaokunyang in https://github.com/apache/fory/pull/4052
Other Improvements
- docs(release): preserve RCs for infrastructure retries by @chaokunyang in https://github.com/apache/fory/pull/4043
- docs: update release version to 1.7.3 by @chaokunyang in https://github.com/apache/fory/pull/4050
New Contributors
- @aditya0za005-ux made their first contribution in https://github.com/apache/fory/pull/4048
Full Changelog: https://github.com/apache/fory/compare/v1.7.3...v1.7.4
- v1.7.32026-09-15 · 2026-09-15 17:27 UTC
查看更新说明
Highlights
- Go now supports the Standard Row Format, with struct encoding and direct access to fields and collection elements without decoding the entire row. This enables row data exchange with Java, C++, Python, and Rust.
- Faster Java JSON reading and writing, including floating-point conversion and parsing timestamps with time zones.
- Kotlin JSON now honors property inclusion settings, including
NON_EMPTY, across supported JVM, GraalVM Native Image, and Android paths.
Features
- perf(java): accelerate JSON floating-point conversion with integer bounds by @chaokunyang in https://github.com/apache/fory/pull/4031
- perf(java): optimize json perf write/read performance by @chaokunyang in https://github.com/apache/fory/pull/4034
- feat(java): optimize json float converter by @chaokunyang in https://github.com/apache/fory/pull/4036
- feat(java): optimize json write/read perf by @chaokunyang in https://github.com/apache/fory/pull/4037
- feat(go): support native fory row format by @ayush00git in https://github.com/apache/fory/pull/3901
- perf(java): optimize timezone json read performance by @chaokunyang in https://github.com/apache/fory/pull/4042
Bug Fix
- fix(java): restore contexts for nested Externalizable callbacks by @chaokunyang in https://github.com/apache/fory/pull/4038
- fix(json): honor Kotlin property inclusion by @chaokunyang in https://github.com/apache/fory/pull/4040
- fix(android): align Kotlin JSON inclusion assertions by @chaokunyang in https://github.com/apache/fory/pull/4041
- fix(java): Fix inconsistency in exception handling when reading EOF stream by @wuwangben in https://github.com/apache/fory/pull/2821
Other Improvements
- chore(deps): upgrade grpc-go to 1.83.1 by @chaokunyang in https://github.com/apache/fory/pull/4029
- chore: Bump js-yaml in /javascript by @dependabot[bot] in https://github.com/apache/fory/pull/4030
Full Changelog: https://github.com/apache/fory/compare/v1.7.2...v1.7.3
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Apache Fory™ is a blazingly fast multi-language serialization framework for idiomatic domain objects, schema IDL, and cross-language data exchange.
Why Fory
Fory is built for fast, compact serialization across languages and implementations. It works with idiomatic objects in each language, supports shared schemas when you need a contract, and preserves object features such as shared and circular references.
- Efficient Cross-Language Encoding: Exchange payloads across supported languages with compact binary encoding, metadata packing, schema evolution, shared/circular references, and polymorphic runtime types.
- Domain Objects First: Serialize Java classes, Python dataclasses, Go structs, Rust/C++ structs, and generated or annotated model types directly. Preserve shared and circular references when object identity matters.
- Reference-Aware Schema IDL: Support shared and circular references directly in the schema, alongside numbers, strings, lists, maps, arrays, enums, structs, and unions. Define schemas once, then generate native domain objects for each language without forcing wrapper types into user code.
- Optimized Implementations: Java JIT serializers and generated/static serializers in other language implementations keep hot paths fast and payloads compact.
- Language And Platform Support: Java, Python, C++, Go, Rust, JavaScript/TypeScript, C#, Swift, Dart, Scala, and Kotlin, including GraalVM native image, Android, Dart VM/Flutter/web, and Node.js/browser JavaScript.
For same-language workloads, Fory provides native serialization modes that support broader language-specific object models:
- Java Native Serialization: A high-performance replacement for JDK serialization, Hessian, Kryo, and FST in Java-only systems. It supports JDK custom serialization semantics.
- Python Native Serialization: A faster and more compact replacement for
pickleandcloudpicklein Python-only systems. It supports classes, modules, functions, and custom object state, with fine-grained deserialization controls throughDeserializationPolicy.
Fory also provides specialized formats for other data-processing requirements:
- Row Format: Read fields, arrays, and nested values without rebuilding complete objects, with zero-copy access and partial reads.
- Fory JSON: A Java JSON serialization framework built for maximum throughput through runtime-generated codecs and optimized readers and writers. Supports Java 8 and later on standard JDKs, GraalVM native images, and Android, including Java 17 records.
Performance
Benchmarks show Fory delivering higher throughput and smaller serialized payloads than common serialization frameworks on representative workloads. Java has the broadest comparison set; the other charts show language-specific results across supported languages.
Java Benchmarks
In Java serialization benchmarks, Fory reaches up to 170x the throughput of JDK serialization on selected workloads.
Python Benchmarks
Rust Benchmarks
C++ Benchmarks
Go Benchmarks
JavaScript/TypeScript Benchmarks
C# Benchmarks
Swift Benchmarks
Dart Benchmarks
Installation
Pick your language and run the package-manager command, or paste the dependency block into your build file.
Java
Maven:
<dependency>
<groupId>org.apache.fory</groupId>
<artifactId>fory-core</artifactId>
<version>1.7.7</version>
</dependency>
Gradle:
implementation "org.apache.fory:fory-core:1.7.7"
On JDK25+, opening java.lang.invoke to Fory core is also recommended. It avoids the
current-JDK Unsafe fallback and is required when Unsafe access is disabled or unavailable, including
with --sun-misc-unsafe-memory-access=deny. Use ALL-UNNAMED when Fory is on the classpath:
--add-opens=java.base/java.lang.invoke=ALL-UNNAMED
Use the Fory core module name when Fory is on the module path:
--add-opens=java.base/java.lang.invoke=org.apache.fory.core
Scala
sbt:
libraryDependencies += "org.apache.fory" %% "fory-scala" % "1.7.7"
Kotlin
Gradle:
implementation("org.apache.fory:fory-kotlin:1.7.7")
Maven:
<dependency>
<groupId>org.apache.fory</groupId>
<artifactId>fory-kotlin</artifactId>
<version>1.7.7</version>
</dependency>
Python
pip install pyfory
For row-format support:
pip install "pyfory[format]"
Rust
Cargo.toml:
[dependencies]
fory = "1.7.7"
C++
CMake:
include(FetchContent)
FetchContent_Declare(
fory
GIT_REPOSITORY https://github.com/apache/fory.git
GIT_TAG v1.7.7
SOURCE_SUBDIR cpp
)
FetchContent_MakeAvailable(fory)
target_link_libraries(my_app PRIVATE fory::serialization)
Bazel:
# MODULE.bazel
bazel_dep(name = "fory", version = "1.7.7")
git_override(module_name = "fory", remote = "https://github.com/apache/fory.git", commit = "v1.7.7")
# BUILD
deps = ["@fory//cpp/fory/serialization:fory_serialization"]
When building C++ with MSVC, enable the conforming preprocessor option
/Zc:preprocessor; see the C++ installation guide for setup details.
See the C++ installation guide for complete CMake, Bazel, and source-build details.
Go
go get github.com/apache/fory/go/fory
JavaScript/TypeScript
npm install @apache-fory/core
For the Node.js string fast path:
npm install @apache-fory/core @apache-fory/hps
C#
dotnet add package Apache.Fory --version 1.7.7
Dart
dart pub add fory:^1.7.7
dart pub add dev:build_runner
Swift
Add Fory to Package.swift:
dependencies: [
.package(url: "https://github.com/apache/fory.git", exact: "1.7.7")
],
targets: [
.target(
name: "YourTarget",
dependencies: [.product(name: "Fory", package: "fory")]
)
]
See the Swift guide for generated serializer setup.
Development From Source
See docs/development/index.md.
Snapshots for Java, Scala, and Kotlin are available from
https://repository.apache.org/snapshots/ with the matching -SNAPSHOT version.
Choose a Serialization Format
| Format | Use it when | Start here |
|---|---|---|
| Xlang binary (default) | Data crosses language boundaries | Cross-language interoperability |
| Native binary | Producer and consumer are in the same runtime family | Native guide |
| Row format | You need random field access or analytics-style partial reads | Row Format |
| Fory JSON | Java applications need high-performance standard JSON | Fory JSON |
For Java, Scala, Kotlin, Python, C++, Go, and Rust, use native mode for same-language traffic. It avoids xlang's cross-language type mapping and metadata constraints, stays closer to each language's native type system, and supports broader language-specific object graphs. Use it when both producer and consumer are in the same language family and you want the native object model rather than a portable cross-language schema.
For Java/JVM-only systems, native mode is the replacement path for JDK serialization, Kryo, FST, Hessian, and Java-only Protocol Buffers payloads. For Python-only systems, native mode is the replacement path for pickle and cloudpickle.
Compatible mode is Fory's schema-evolution mode. It writes the metadata readers and writers need to tolerate schema differences. It is the default for xlang mode and native mode in implementations that expose the option.
Use compatible mode when services deploy independently or when fields may be
added or deleted over time. Set compatible mode to false only when every reader
and writer always uses the same schema and you want faster serialization and
smaller size. For xlang payloads, set compatible mode to false only after
verifying that every language uses the same schema, or when native types are
generated from Fory schema IDL.
For xlang, all peers must agree on type identity. Name-based registration is easier to read in examples. Numeric IDs are smaller and faster, but they require coordination across every reader and writer.
Cross-Language Serialization
Xlang mode writes the cross-language Fory wire format. Bytes produced by one language implementation can be read by another when every peer uses the same type identity, compatible mode setting, and field schema.
Java
import org.apache.fory.Fory;
public class Example {
public static class Person {
public String name;
public int age;
}
public static void main(String[] args) {
Fory fory = Fory.builder().withXlang(true).build();
fory.register(Person.class, "example.Person");
Person person = new Person();
person.name = "Alice";
person.age = 30;
byte[] bytes = fory.serialize(person);
Person decoded = (Person) fory.deserialize(bytes);
System.out.println(decoded.name);
}
}
Python
from dataclasses import dataclass
import pyfory
@dataclass
class Person:
name: str
age: pyfory.Int32
fory = pyfory.Fory(xlang=True)
fory.register_type(Person, name="example.Person")
data = fory.serialize(Person("Alice", 30))
person = fory.deserialize(data)
print(person.name)
Go
package main
import (
"fmt"
"github.com/apache/fory/go/fory"
)
type Person struct {
Name string
Age int32
}
func main() {
f := fory.New(fory.WithXlang(true))
if err := f.RegisterStructByName(Person{}, "example.Person"); err != nil {
panic(err)
}
data, _ := f.Serialize(&Person{Name: "Alice", Age: 30})
var person Person
if err := f.Deserialize(data, &person); err != nil {
panic(err)
}
fmt.Println(person.Name)
}
Rust
use fory::{Error, Fory, ForyStruct};
#[derive(ForyStruct, Debug, PartialEq)]
struct Person {
name: String,
age: i32,
}
fn main() -> Result<(), Error> {
let mut fory = Fory::builder().xlang(true).build();
fory.register_by_name::<Person>("example.Person")?;
let bytes = fory.serialize(&Person {
name: "Alice".to_string(),
age: 30,
})?;
let person: Person = fory.deserialize(&bytes)?;
println!("{}", person.name);
Ok(())
}
C++
#include "fory/serialization/fory.h"
#include <cstdint>
#include <iostream>
#include <string>
using namespace fory::serialization;
struct Person {
std::string name;
int32_t age;
};
FORY_STRUCT(Person, name, age);
int main() {
auto fory = Fory::builder().xlang(true).build();
fory.register_struct<Person>("example.Person");
auto bytes = fory.serialize(Person{"Alice", 30}).value();
Person person = fory.deserialize<Person>(bytes).value();
std::cout << person.name << std::endl;
}
JavaScript/TypeScript
import Fory, { Type } from "@apache-fory/core";
const personType = Type.struct(
{ typeName: "example.Person" },
{
name: Type.string(),
age: Type.int32(),
},
);
const fory = new Fory();
const { serialize, deserialize } = fory.register(personType);
const bytes = serialize({ name: "Alice", age: 30 });
const person = deserialize(bytes);
console.log(person.name);
C#
using Apache.Fory;
[ForyStruct]
public sealed class Person
{
public string Name { get; set; } = string.Empty;
public int Age { get; set; }
}
Fory fory = Fory.Builder().Build();
fory.Register<Person>("example", "Person");
byte[] bytes = fory.Serialize(new Person { Name = "Alice", Age = 30 });
Person person = fory.Deserialize<Person>(bytes);
Console.WriteLine(person.Name);
C# always writes the xlang frame header, so there is no separate xlang builder flag.
Dart
import 'package:fory/fory.dart';
part 'person.fory.dart';
@ForyStruct()
class Person {
Person();
String name = '';
@ForyField(type: Int32Type())
int age = 0;
}
void main() {
final fory = Fory();
PersonFory.register(
fory,
Person,
name: 'example.Person',
);
final bytes = fory.serialize(Person()
..name = 'Alice'
..age = 30);
final person = fory.deserialize<Person>(bytes);
print(person.name);
}
Dart uses the xlang wire format directly. Generate the companion file before running:
dart run build_runner build
Swift
import Fory
@ForyStruct
struct Person {
var name: String = ""
var age: Int32 = 0
}
let fory = Fory()
try fory.register(Person.self, name: "example.Person")
let bytes = try fory.serialize(Person(name: "Alice", age: 30))
let person: Person = try fory.deserialize(bytes)
print(person.name)
Scala
import org.apache.fory.scala.ForyScala
case class Person(name: String, age: Int)
val fory = ForyScala.builder().withXlang(true).build()
fory.register(classOf[Person], "example.Person")
val bytes = fory.serialize(Person("Alice", 30))
val person = fory.deserialize(bytes).asInstanceOf[Person]
println(person.name)
Kotlin
import org.apache.fory.kotlin.ForyKotlin
data class Person(val name: String, val age: Int)
fun main() {
val fory = ForyKotlin.builder().withXlang(true).build()
fory.register(Person::class.java, "example.Person")
val bytes = fory.serialize(Person("Alice", 30))
val person = fory.deserialize(bytes) as Person
println(person.name)
}
For shared/circular references, polymorphism, numeric IDs versus names, and type-mapping rules, see the cross-language guide and type mapping specification.
Native Serialization
Use native mode when the writer and reader are in the same language. It is
optimized for each language's native type system and can cover language-specific
types, object graphs, and framework-replacement cases that xlang mode keeps out
of the portable wire format. The languages below expose an explicit
xlang=false or native-mode setting; implementations without that switch stay on their
documented default path.
Choose Java native mode for Java/JVM-only replacements of JDK serialization, Kryo, FST, Hessian, or Java-only Protocol Buffers payloads. Choose Python native mode when replacing pickle or cloudpickle for Python-only payloads.
Keep class/type registration enabled for untrusted input. See the language guides for language-specific security and compatibility settings.
Java
Fory fory = Fory.builder()
.withXlang(false)
.requireClassRegistration(true)
.build();
// Register, serialize, and deserialize as in the xlang example above.
Python
fory = pyfory.Fory(xlang=False, ref=True)
# Register, serialize, and deserialize as in the xlang example above.
Go
f := fory.New(fory.WithXlang(false))
// Register, serialize, and deserialize as in the xlang example above.
Rust
let mut fory = Fory::builder().xlang(false).build();
// Register, serialize, and deserialize as in the xlang example above.
C++
auto fory = Fory::builder().xlang(false).build();
// Register, serialize, and deserialize as in the xlang example above.
Scala
import org.apache.fory.scala.ForyScala
val fory = ForyScala.builder()
.withXlang(false)
.requireClassRegistration(true)
.build()
// Register, serialize, and deserialize as in the xlang example above.
Kotlin
import org.apache.fory.kotlin.ForyKotlin
val fory = ForyKotlin.builder()
.withXlang(false)
.requireClassRegistration(true)
.build()
// Register, serialize, and deserialize as in the xlang example above.
Schema IDL
Fory IDL is Fory's schema-first path for shared data models. Use it when multiple languages need one explicit contract, stable field identities, and generated native domain objects instead of manually coordinating equivalent types in every implementation.
The schema supports primitive values, nullable fields, lists, maps, dense arrays, enums, messages, unions, imports, and first-class shared or circular references. The compiler generates idiomatic models and Fory integration for Java, Python, C++, Go, Rust, JavaScript/TypeScript, C#, Swift, Dart, Scala, and Kotlin. It can also generate Fory-backed gRPC service companions for supported languages.
Install the compiler from PyPI:
pip install fory-compiler
Define the shared model in tree.fdl:
package tree;
message TreeNode {
string id = 1;
string name = 2;
list<ref TreeNode> children = 3;
ref(weak=true) TreeNode parent = 4; // back-pointer
}
Generate native models for the languages used by your application:
foryc tree.fdl --lang java,python,rust --output ./generated
Generated types use each language's normal classes, structs, dataclasses, annotations, macros, or registration helpers, so application code works with native domain objects while all peers share the same Fory schema. See the Fory IDL and compiler guide for the complete type system, language-specific output options, schema evolution, and gRPC generation.
Row Format
Row format is for random access and partial reads. These examples encode an object with an integer array field, then read one array element from the binary row without rebuilding the object.
Python
from dataclasses import dataclass
from typing import List
import pyfory
@dataclass
class User:
id: pyfory.Int32
name: str
scores: List[pyfory.Int32]
encoder = pyfory.encoder(User)
binary = encoder.to_row(User(1, "Alice", [98, 100, 95])).to_bytes()
row = pyfory.RowData(encoder.schema, binary)
print(row.name)
print(row.scores[1])
Java
public class User {
public int id;
public String name;
public int[] scores;
}
RowEncoder<User> encoder = Encoders.bean(User.class);
User user = new User();
user.id = 1;
user.name = "Alice";
user.scores = new int[] {98, 100, 95};
BinaryRow row = encoder.toRow(user);
Schema schema = encoder.schema();
Schema.StringField nameField = schema.stringField("name");
Schema.ArrayField scoresField = schema.arrayField("scores");
String name = nameField.get(row);
ArrayData scores = scoresField.get(row);
int secondScore = scores.getInt32(1);
Go
import "github.com/apache/fory/go/fory/row"
type User struct {
Id int32
Name string
Scores []int32
}
encoder, _ := row.NewEncoder[User]()
binary, _ := encoder.ToRow(&User{Id: 1, Name: "Alice", Scores: []int32{98, 100, 95}})
schema := encoder.Schema()
r := row.NewRow(schema, binary)
name := r.String(schema.FieldIndex("name"))
secondScore := r.Array(schema.FieldIndex("scores")).Int32(1)
For Java imports, nested structs, arrays/maps, Arrow integration, and partial deserialization, see the Java row-format guide, Python row-format guide, C++ row-format guide, Rust row-format guide, Go row-format guide, and row-format specification.
Fory JSON
Fory JSON is a thread-safe JSON serialization framework for Java, extensively optimized for maximum performance across JSON encoding, decoding, and Java object mapping. It supports Java 8 and later on standard JDKs, GraalVM native images, and Android, with Java records supported on Java 17 and later.
Performance
The benchmark compares fory-json with Jackson and Gson using String and UTF-8 byte APIs. The String group excludes UTF-8 conversion. Gson's byte results include its required String/UTF-8 conversion. Higher throughput is better. See the full benchmark report for more details.
| Representation | Operation | fory-json ops/sec | Jackson ops/sec | Gson ops/sec |
|---|---|---|---|---|
| String | Serialize | 7,387,465 | 2,049,368 | 1,084,042 |
| String | Deserialize | 2,897,955 | 1,074,885 | 902,772 |
| UTF-8 bytes | Serialize | 10,375,498 | 1,868,614 | 1,037,211 |
| UTF-8 bytes | Deserialize | 3,077,158 | 1,268,397 | 933,079 |
Add Fory JSON to your project:
Maven
<dependency>
<groupId>org.apache.fory</groupId>
<artifactId>fory-json</artifactId>
<version>1.7.7</version>
</dependency>
Gradle
implementation "org.apache.fory:fory-json:1.7.7"
Keep all Fory modules in the same application on the same version.
Quick Start
Build one ForyJson instance and reuse it across threads:
import org.apache.fory.json.ForyJson;
public final class JsonExample {
private static final ForyJson JSON = ForyJson.builder().build();
public static final class User {
public long id;
public String name;
public User() {}
public User(long id, String name) {
this.id = id;
this.name = name;
}
}
public static void main(String[] args) {
User input = new User(7, "Alice");
String text = JSON.toJson(input);
User fromText = JSON.fromJson(text, User.class);
byte[] bytes = JSON.toJsonBytes(input);
User fromBytes = JSON.fromJson(bytes, User.class);
System.out.println(fromText.name + " / " + fromBytes.name);
}
}
Start with the Fory JSON module README, then use the Fory JSON documentation for the complete mapping, annotation, codec, security, and platform guides.
Documentation
User Guides
| Guide | Source | Website |
|---|---|---|
| Java | docs/object-serialization/java | View |
| Python | docs/object-serialization/python | View |
| Rust | docs/object-serialization/rust | View |
| C++ | docs/object-serialization/cpp | View |
| Go | docs/object-serialization/go | View |
| JavaScript/TypeScript | docs/object-serialization/javascript | View |
| C# | docs/object-serialization/csharp | View |
| Swift | docs/object-serialization/swift | View |
| Dart | docs/object-serialization/dart | View |
| Scala | docs/object-serialization/scala | View |
| Kotlin | docs/object-serialization/kotlin | View |
| Cross-language xlang | docs/object-serialization/xlang.md | View |
| Schema IDL/compiler | docs/compiler | View |
| GraalVM native image | docs/object-serialization/java/graalvm.md | View |
| Android | docs/object-serialization/java/android.md | View |
| Development | docs/development/index.md | View |
Specifications
| Specification | Source | Website |
|---|---|---|
| Xlang serialization | xlang_serialization_spec.md | View |
| Java serialization | java_serialization_spec.md | View |
| Row format | row_format_spec.md | View |
| Cross-language mapping | xlang_type_mapping.md | View |
Community
- Slack workspace
- @ApacheFory on X
- GitHub issues
- Apache Fory mailing lists for development discussion
Contributing
Read CONTRIBUTING.md and docs/development/index.md before sending pull requests. Bug reports, docs fixes, tests, benchmarks, and implementation improvements are welcome.
License
Apache Fory™ is licensed under the Apache License 2.0.