📖 English Documentation | 📖 中文文档
本项目的Issues会被同步沉淀至阿里云开发者社区
FASTJSON 2
是一个性能极致并且简单易用的Java JSON库。
FASTJSON 2
是FASTJSON
项目的重要升级,和FASTJSON 1相比,性能有非常大的提升,解决了autoType功能因为兼容和白名单的安全性问题。- 性能极致,性能远超过其他流行JSON库,包括jackson/gson/org.json,性能数据: https://github.com/alibaba/fastjson2/wiki/fastjson_benchmark
- 支持JDK新特性,包括
JDK 11
/JDK 17
,针对compact string
优化,支持Record,支持GraalVM Native-Image
- 完善的
JSONPath
支持,支持SQL:2016的JSONPath语法 - 支持
Android 8+
,客户端和服务器一套API - 支持
Kotlin
https://alibaba.github.io/fastjson2/kotlin_cn - 支持
JSON Schema
https://alibaba.github.io/fastjson2/json_schema_cn - 新增加支持二进制格式JSONB https://alibaba.github.io/fastjson2/jsonb_format_cn
在fastjson v2
中,groupId
和1.x
不一样,是com.alibaba.fastjson2
:
Maven
:
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.57</version>
</dependency>
Gradle
:
dependencies {
implementation 'com.alibaba.fastjson2:fastjson2:2.0.57'
}
可以在 maven.org 查看最新可用的版本。
如果原来使用fastjson 1.2.x
版本,可以使用兼容包,兼容包不能保证100%兼容,请仔细测试验证,发现问题请及时反馈。
Maven
:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.57</version>
</dependency>
Gradle
:
dependencies {
implementation 'com.alibaba:fastjson:2.0.57'
}
如果项目使用Kotlin
,可以使用fastjson-kotlin
模块,使用方式上采用kotlin
的特性。
Maven
:
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-kotlin</artifactId>
<version>2.0.57</version>
</dependency>
酌情添加标准库(kotlin-stdlib)、反射库(kotlin-reflect), 其中若使用数据类(data class)、通过构造函数传入参数则添加反射库。
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin-version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin-version}</version>
</dependency>
Kotlin Gradle
:
dependencies {
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.57")
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version")
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlin_version")
}
如果项目使用SpringFramework
等框架,可以使用fastjson-extension
模块,使用方式参考 SpringFramework Support。
Maven
:
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension-spring5</artifactId>
<version>2.0.57</version>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension-spring6</artifactId>
<version>2.0.57</version>
</dependency>
Gradle
:
dependencies {
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring5:2.0.57'
}