Gson

本文介绍 Gson 序列化

1 介绍

Gson是Google公司发布的一个开放源代码的Java库,主要用途为序列化Java对象为JSON字符串,或反序列化JSON字符串成Java对象。

2 使用方式

2.1 添加依赖

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.apache.dubbo.extensions</groupId>
  4. <artifactId>dubbo-serialization-gson</artifactId>
  5. <version>3.3.0</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>com.google.code.gson</groupId>
  9. <artifactId>gson</artifactId>
  10. <version>2.10.1</version>
  11. </dependency>
  12. </dependencies>

2.2 配置启用

  1. # application.yml (Spring Boot)
  2. dubbo:
  3. protocol:
  4. serialization: gson

  1. # dubbo.properties
  2. dubbo.protocol.serialization=gson
  3. # or
  4. dubbo.consumer.serialization=gson
  5. # or
  6. dubbo.reference.com.demo.DemoService.serialization=gson

  1. <dubbo:protocol serialization="gson" />
  2. <!-- or -->
  3. <dubbo:consumer serialization="gson" />
  4. <!-- or -->
  5. <dubbo:reference interface="xxx" serialization="gson" />

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