Serialization Extension

Serialization Extension

Extension Description

Convert objects into byte streams for network transmission, and convert byte streams into objects for restoring the received byte stream data back into objects.

Extension Interfaces

  • org.apache.dubbo.common.serialize.Serialization
  • org.apache.dubbo.common.serialize.ObjectInput
  • org.apache.dubbo.common.serialize.ObjectOutput

Extension Configuration

  1. <!-- Serialization method for the protocol -->
  2. <dubbo:protocol serialization="xxx" />
  3. <!-- Default value setting, when <dubbo:protocol> does not configure serialization, use this configuration -->
  4. <dubbo:provider serialization="xxx" />

Known Extensions

  • org.apache.dubbo.common.serialize.dubbo.DubboSerialization
  • org.apache.dubbo.common.serialize.hessian.Hessian2Serialization
  • org.apache.dubbo.common.serialize.java.JavaSerialization
  • org.apache.dubbo.common.serialize.java.CompactedJavaSerialization

Extension Example

Maven project structure:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxSerialization.java (implements Serialization interface)
  7. |-XxxObjectInput.java (implements ObjectInput interface)
  8. |-XxxObjectOutput.java (implements ObjectOutput interface)
  9. |-resources
  10. |-META-INF
  11. |-dubbo
  12. |-org.apache.dubbo.common.serialize.Serialization (plain text file, content: xxx=com.xxx.XxxSerialization)

XxxSerialization.java:

  1. package com.xxx;
  2. import org.apache.dubbo.common.serialize.Serialization;
  3. import org.apache.dubbo.common.serialize.ObjectInput;
  4. import org.apache.dubbo.common.serialize.ObjectOutput;
  5. public class XxxSerialization implements Serialization {
  6. public ObjectOutput serialize(Parameters parameters, OutputStream output) throws IOException {
  7. return new XxxObjectOutput(output);
  8. }
  9. public ObjectInput deserialize(Parameters parameters, InputStream input) throws IOException {
  10. return new XxxObjectInput(input);
  11. }
  12. }

META-INF/dubbo/org.apache.dubbo.common.serialize.Serialization:

  1. xxx=com.xxx.XxxSerialization

Feedback

Was this page helpful?

Yes No

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