Fastjson2

Fastjson2

本文介绍 Fastjson2 序列化

1 介绍

FASTJSON v2是FASTJSON项目的重要升级,目标是为下一个十年提供一个高性能的JSON库。通过同一套API,

  • 支持JSON/JSONB两种协议,JSONPath 是一等公民。
  • 支持全量解析和部分解析。
  • 支持Java服务端、客户端Android、大数据场景。
  • 支持Kotlin <https://alibaba.github.io/fastjson2/kotlin_cn>
  • 支持JSON Schema <https://alibaba.github.io/fastjson2/json_schema_cn>
  • 支持Android 8+
  • 支持Graal Native-Image
  • 支持 JSON Schema <https://alibaba.github.io/fastjson2/json_schema_cn>

2 使用方式

2.1 添加依赖

<dependencies>
    <dependency>
        <groupId>com.alibaba.fastjson2</groupId>
        <artifactId>fastjson2</artifactId>
        <version>2.0.23</version>
    </dependency>
</dependencies>

注:Fastjson2 序列化仅 Dubbo > 3.1.0 版本支持。在 Dubbo > 3.2.0 中将替代 Hessian 作为默认序列化方式。

2.2 配置启用

## application.yml (Spring Boot)
dubbo:
 protocol:
   serialization: fastjson2

或

## dubbo.properties
dubbo.protocol.serialization=fastjson2

## or
dubbo.consumer.serialization=fastjson2

## or
dubbo.reference.com.demo.DemoService.serialization=fastjson2

或

<dubbo:protocol serialization="fastjson2" />

<!-- or -->
<dubbo:consumer serialization="fastjson2" />

<!-- or -->
<dubbo:reference interface="xxx" serialization="fastjson2" />

最后修改 September 13, 2024: Refactor website structure (#2860) (1a4b998f54b)