fastjson2: Alibaba's Java JSON library, and the AutoType problem that shaped it
🚄 FASTJSON2 is a Java JSON library with excellent performance.
At a glance
- What is it?
- A rewrite of the fastjson library with a binary JSONB format, JSONPath, JSON Schema and Kotlin support, with AutoType disabled by default.
- Who is it for?
- fastjson2 is a good fit when you want a drop-in JSON layer on Java 8 through 21 with a binary format. One decision matters more than any benchmark: leave AutoType off, as it is by default, unless you genuinely need polymorphic deserialization.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 11 days ago.
- What is it written in?
- Mainly Java, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- alibaba/fastjson24,431 ★ · +15
| Repository | 2026-10-07 | 2026-11-25 |
|---|---|---|
| alibaba/fastjson2 | 4.4k | 4.4k |
15 Stars in the last 49 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Adding the dependency and parsing on the first line
The quick start is a Maven dependency and a static import. The groupId changed from the 1.x line, which is the first thing that trips up an upgrade:
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.66</version>
</dependency>With Gradle the same coordinate reads as one line:
dependencies {
implementation 'com.alibaba.fastjson2:fastjson2:2.0.66'
}The whole API is reachable through the `JSON` facade, and the README's example is short enough to be the entire mental model:
import com.alibaba.fastjson2.JSON;
// Parse
User user = JSON.parseObject("{\"name\":\"John\",\"age\":25}", User.class);
// Serialize
String json = JSON.toJSONString(user);Parse with `parseObject`, serialize with `toJSONString`. The same facade also gives you `JSONObject` and `JSONArray` for the untyped case, and bean serialization is configured through annotations, features, filters or custom serializers.
The README targets JDK 8, 11, 17 and 21, and claims compact string, Record and Vector API support, so a JDK 8 service and a JDK 21 service can share a dependency version. Kotlin projects take a separate `fastjson2-kotlin` module with an idiomatic DSL, and the README notes that the reflection library is needed for data classes and constructor-based parameter passing.
JSONB, JSONPath and JSON Schema beyond parse and print
The features that separate fastjson2 from a basic object mapper are the extras in the advanced section of the README.
JSONB is the binary counterpart to JSON text, documented on its own page, and the README lists native support for both protocols. That matters for big-data pipelines, which the README names as a target platform.
JSONPath is supported and described as SQL:2016 compatible, so you can extract one field out of a large document without materializing the rest. The repository tree shows `core/` holding the main implementation and `docs/` the documentation sources, with `codegen/` for generated sources.
JSON Schema validation is built in, which is a differentiator. Most Java JSON libraries leave validation to a separate library such as a networknt schema validator, so having it in the same dependency saves adding another one.
The library also targets Android 8 and up, and the repository carries an android-test/ module, so this is not only a server-side library. GraalVM Native Image compatibility is listed as a highlight.
Spring integration is modular rather than assumed: the tree has `extension-spring5/`, `extension-spring6/`, `extension-jaxrs/` and `extension-solon/`, with matching example test modules, so a Spring application picks the extension matching its generation.
AutoType is off by default, and that is the whole security story
fastjson's reputation comes from AutoType, the feature that lets JSON name the class it should be deserialized into. It is also the source of a long line of remote code execution issues in the 1.x line.
The design position is stated in the highlights: AutoType disabled by default, no hardcoded whitelist, SafeMode support. That is a direct contrast with 1.x, where a global parser configuration could be turned on in one place and affect every parse in the process.
The practical reading is straightforward. If you do not need polymorphic deserialization, do not enable AutoType. If you do, treat it as an attack surface and pin to a current patch version.
Migrating from fastjson 1.x through a compatibility module
For an existing codebase, the fastjson2 tree carries a `fastjson1-compatible/` module that lets you change coordinates without rewriting calls first. It ships under the old groupId:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.66</version>
</dependency>That swap pulls the compatibility implementation in place of the 1.x library, so imports like `com.alibaba.fastjson.JSON` keep resolving while the implementation underneath is fastjson2's.
The README is careful about the limits, saying that 100% compatibility is not guaranteed and asking you to test thoroughly and report issues.
A sensible migration is therefore staged: swap to the compatibility artifact, run the full test suite with AutoType still off, then decide per service whether the native fastjson2 API is worth the churn. The Kotlin module is a separate decision again, since the extension DSL is a different surface rather than a compat shim.
How this compares with Jackson and Gson
The README's performance claim is direct: fastjson2 significantly outperforms Jackson, Gson and `org.json`, with a benchmark link to a wiki page. It does not put numbers in the README itself, and the benchmark module in the tree is named `benchmark/` and `benchmark_25/`, so the comparison lives outside the documentation you read first.
The more durable differences are structural.
Jackson is the reference implementation for data binding in the JVM ecosystem, with deep Spring integration and the largest body of Stack Overflow answers. Its cost is configuration surface and annotation vocabulary, and its stream-based API is a bigger rewrite than a static facade.
Gson is the smallest of the three and stays out of the way, but it has no binary format, no JSONPath and no schema validation, so those all come as extra dependencies.
fastjson2's distinctive combination is that JSONB, JSONPath, JSON Schema and AutoType-style type hints all arrive in one artifact, which is attractive when you are parsing heterogeneous payloads from many upstream systems. The offsetting cost is that AutoType exists at all.
For a team that only needs clean bean mapping and already has Jackson on the classpath, the argument for switching is thin. For a pipeline reading large binary documents or validating against a schema at the edge, the extra features are the reason to look.
Repository layout, build tooling and where the README cuts off
The repository is a Maven multi-module build with a wrapper committed, `mvnw` and `mvnw.cmd`, so building does not require a local Maven install. Alongside `pom.xml` there are `test-jdk17/` and `test-jdk25/` modules, which is how the project checks that the same code still compiles and passes on newer JDKs than the 8 baseline it claims.
There is also `safemode-test/`, a dedicated module for the SafeMode mitigation path, which tells you the security mode is treated as a tested configuration rather than a documented afterthought. CI runs through GitHub Actions on the `main` branch, with a Codecov badge for coverage.
The README is bilingual, with `README_cn.md` beside it, and it covers installation for the core library, the 1.x compatibility module, the Kotlin module and the Spring 5 and 6 extensions, with a fuller Spring Integration Guide under `docs/`.
Licensing is Apache-2.0, and there is a `SECURITY.md` alongside `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md` and an `AGENTS.md`.
The last push to the repository was on 2026-10-30, and the latest release is 2.0.66 from 2026-10-17, after 2.0.65 on 2026-09-02 and 2.0.64 on 2026-08-02.
Editorial conclusion
fastjson2 is a good fit when you want a drop-in JSON layer on Java 8 through 21 with a binary format. One decision matters more than any benchmark: leave AutoType off, as it is by default, unless you genuinely need polymorphic deserialization. For a migration from fastjson 1.x, the compatibility module under groupId `com.alibaba` saves real work, but the README states plainly that full compatibility is not guaranteed. Compare the API surface against Jackson before switching.
Frequently asked questions
Which JSON serializer is best for Java?
It depends on what you need beyond bean mapping. Jackson is the safest default for Spring applications because of its ecosystem. fastjson2 earns its place when you want JSONB, JSONPath and JSON Schema in the same artifact, or when you are on Android or GraalVM. The deciding factor is often whether you need those extras at all.
What are the best JSON libraries for Java?
The three the README names in its performance comparison are Jackson, Gson and `org.json`, with fastjson2 claiming to outperform them, and Gson is the one to pick when you want the smallest dependency with no configuration. fastjson2 is the one to pick when binary JSONB, SQL:2016 compatible JSONPath and built-in JSON Schema validation matter more than a small API surface.
What should I do if I cannot upgrade past an affected fastjson2 version right away?
The README lists SafeMode support among its security highlights, alongside AutoType being disabled by default, and the repository carries a dedicated safemode-test module. Keep AutoType off unless you need it.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/alibaba-fastjson2)Star history chart for your README
[](https://hysenlabs.com/projects/alibaba-fastjson2)Was this useful?