Apache Fory JSON: Fastest Java JSON Serialization, 10x Faster Than Jackson/Gson

chaokunyang1 pts1 comments

Introducing Apache Fory™ JSON: Blazingly Fast JSON Serialization for Java | Apache Fory™

Skip to main content<br>TL;DR : Apache Fory JSON is a high-performance serialization framework that maps Java objects to and from standard JSON text and UTF-8 bytes. It supports common Java models and runs on JDK 8+, Android, and GraalVM Native Image. Fory JSON is the fastest Java JSON serialization framework in the published benchmarks: up to 10.91× the throughput of Jackson and 10.89× the throughput of Gson with 1000 KB payloads, and up to 5.55× the throughput of Jackson and 10.00× the throughput of Gson in the jvm-serializers MediaContent benchmark.

GitHub: apache/fory

Documentation: Fory JSON

Wider 1000 KB benchmark context: java-json-benchmark

Why JSON Performance Matters​

JSON sits on many Java service hot paths: HTTP APIs, browser traffic, event payloads, logs, configuration, and integrations with systems that do not share a binary protocol. Parsing and serialization costs recur across requests, consuming CPU and creating temporary objects.

Fory already provides compact binary object serialization and a cross-language protocol. Fory JSON serves a different use case by mapping Java objects to standard JSON text and UTF-8 bytes. The output remains readable by browsers, command-line tools, and any standards-compliant JSON implementation.

Quick Start​

Fory JSON 1.6.0 is available from Maven Central:

dependency>

groupId>org.apache.forygroupId>

artifactId>fory-jsonartifactId>

version>1.6.0version>

dependency>

Create one ForyJson instance and reuse it. The built instance is immutable and thread-safe.

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() {}

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);

byte[] utf8 = JSON.toJsonBytes(input);

User fromText = JSON.fromJson(text, User.class);

User fromUtf8 = JSON.fromJson(utf8, User.class);

System.out.println(text); // {"id":7,"name":"Alice"}

System.out.println(fromText.name); // Alice

System.out.println(fromUtf8.name); // Alice

Fory JSON directly supports both String and byte-array APIs. For generic roots, a TypeRef> preserves the element type during deserialization and declared-type serialization. Fory JSON can also write a complete UTF-8 document to an OutputStream without taking ownership of the stream.

How Fory JSON Achieves High Performance​

Fory JSON's performance comes primarily from four implementation choices.

Minimal temporary allocation. A ForyJson instance reuses prepared type metadata, execution state, and retained writer buffers. For most basic scalar values, the hot serialization path is effectively zero-allocation beyond the requested output: Fory writes the value directly into its output buffer instead of first converting it into a Java String. Returning a String or byte[] still creates that result, and buffer growth or a cold fallback can allocate.

Highly optimized primitive writes. Integers and longs use direct digit encoders, while floating-point values use direct formatting paths where the JDK provides them. Booleans, numbers, and quoted strings go straight to the active String or UTF-8 writer. There is no per-value String.valueOf(...) round trip on the hot path.

Bulk memory operations. Common Latin-1 and ASCII text is scanned and copied in 8-byte or 16-byte chunks. Generated writers can also use packed property prefixes and object framing, reducing per-character branches and repeated writes.

Runtime code generation. Fory JSON prepares a codec for each Java type it encounters. On a standard JDK, code generation and asynchronous compilation are enabled by default. Generated codecs specialize field access, property names, framing, and primitive operations for the target class instead of rediscovering the same property model on every call. An interpreted path remains available for restricted environments and diagnostics.

The public API preserves those fast paths. Applications that need UTF-8 output can call toJsonBytes and fromJson(byte[], type) directly, while text-oriented code can use the String APIs. Custom codecs also stream through Fory's reader and writer instead of building an intermediate JSON tree.

Performance Benchmarks​

The performance results cover two workloads: a large-payload java-json-benchmark run and the smaller jvm-serializers MediaContent benchmark. Both report throughput in operations per second, so higher is better. Each subsection describes its configuration.

The tables compare Fory JSON only with Jackson and Gson. For the wider large-payload matrix, exact payload setup, and the benchmark integration, see java-json-benchmark.

java-json-benchmark: 1000 KB payloads​

The 1000 KB suite measures workloads in...

json fory java string user serialization

Related Articles