Gson

This article introduces Gson serialization

1 Introduction

Gson is an open-source Java library released by Google, primarily used for serializing Java objects to JSON strings or deserializing JSON strings into Java objects.

2 Usage

2.1 Add Dependency

  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 Configuration Enable

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

or

  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

or

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

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)