English | 简体中文
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.jarin 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
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. |
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.
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)
- 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.
- 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>