Skip to content

Latest commit

 

History

History
117 lines (88 loc) · 7.87 KB

File metadata and controls

117 lines (88 loc) · 7.87 KB

Hessian2 Serialization

Java CI JDK support codecov Coverage Status Quality Gate Status Maintainability Rating Maven Central Last SNAPSHOT GitHub release License zread Average time to resolve an issue

English | 简体中文

Introduction

This project is a refactored and modularized version of the original Hessian repository, with all RPC-related logic removed. It focuses solely on maintaining and enhancing the Hessian serialization protocol.

The new commits are copied from the source code of hessian-4.0.xx-sources.jar in https://repo1.maven.org/maven2/com/caucho/hessian/

The Hessian serialization protocol remains widely used in practice due to the following advantages:

  • High Performance: Fast (de)serialization
  • 📦 Compact Size: Efficient binary encoding
  • 🌐 Cross-language Compatibility: Useful in polyglot systems
  • 🛠️ Ease of use: simple to use, no predefined data structure required

✅ Object Reference Reuse: Hessian2’s Unique Strength

Hessian2 supports shared references and cyclic object graphs out-of-the-box. It detects duplicated object instances and reuses them during serialization, and can correctly handle circular references without stack overflow or infinite loops.

In contrast:

Format Shared References Cyclic References Notes
Hessian2 ✅ Yes ✅ Yes Native support, no special handling
JSON (standard) ❌ No ❌ No By default, only supports value copies; circular references will cause an error. Some JSON libraries provide annotations or custom strategies to support references.
Protobuf ❌ No ❌ No Tree-structured; cannot express shared or circular references. Shared objects must be handled at the application level using IDs or mappings.

🌍 When Hessian2 Still Shines

These features make Hessian2 ideal for scenarios such as:

  • Java object persistence or caching with shared/circular references
  • Deep cloning or snapshotting of runtime state
  • Java-to-Java microservice communication with contextual state
  • RPC frameworks that demand full fidelity object reconstruction

Even in modern systems, Hessian2 remains irreplaceable in certain specialized fields due to its fidelity, compactness, and ease of integration.

Overview of Hessian2 Protocol

Hessian2 is an enhanced version of the original Hessian protocol, with the following features:

  • Binary serialization of Java primitives, collections, and custom classes
  • Object reference support to prevent redundant serialization
  • Class definition caching to reduce payload size
  • Designed for high-efficiency data transmission

📄 Protocol Documentation: Hessian2 Protocol Specification (English)

What’s Special About This Project

  • Strip the RPC-related code from the original Hessian project
  • Modularized architecture for better extensibility and maintenance
  • Supports Hessian 2 protocol only
  • Ideal for use as a standalone, high-efficiency serialization library
  • Supports Java 11 and above versions

Community contributions are welcome. We are committed to keeping a clean, modular, and efficient implementation of the Hessian serialization protocol in Java.

📦 Maven dependency

  • Basic usage

If you only need Hessian serialization/deserialization, simply include the hessian2-codec dependency:

<dependency>
    <groupId>io.github.wuwen5.hessian</groupId>
    <artifactId>hessian2-codec</artifactId>
    <version>0.1.0-SNAPSHOT</version>
</dependency>
  • Using with Dubbo

When integrating with Dubbo, you need to add the hessian-dubbo-adapter module and exclude Dubbo’s built-in hessian-lite dependency:

<dependencies>
  <dependency>
    <groupId>io.github.wuwen5.hessian</groupId>
    <artifactId>hessian2-codec</artifactId>
    <version>0.1.0-SNAPSHOT</version>
  </dependency>
  <dependency>
    <groupId>io.github.wuwen5.hessian</groupId>
    <artifactId>hessian-dubbo-adapter</artifactId>
    <version>0.1.0-SNAPSHOT</version>
  </dependency>
  <dependency>
    <groupId>org.apache.dubbo</groupId>
    <artifactId>dubbo</artifactId>
    <version>${dubbo.version}</version>
    <exclusions>
      <exclusion>
        <groupId>com.alibaba</groupId>
        <artifactId>hessian-lite</artifactId>
      </exclusion>
    </exclusions>
  </dependency>
</dependencies>