Class SerializingCloner

java.lang.Object
cloud.opencode.base.deepclone.cloner.AbstractCloner
cloud.opencode.base.deepclone.cloner.SerializingCloner
All Implemented Interfaces:
Cloner

public final class SerializingCloner extends AbstractCloner
Serialization-based deep cloner 基于序列化的深度克隆器

Uses Java serialization to create deep copies. Objects must implement Serializable interface. Simple but slower than reflection-based cloning.

使用Java序列化创建深度副本。对象必须实现Serializable接口。 简单但比基于反射的克隆慢。

Features | 主要功能:

  • Complete object graph copy - 完整对象图复制
  • Handles circular references automatically - 自动处理循环引用
  • Simple implementation - 实现简单

Limitations | 限制:

  • Objects must implement Serializable - 对象必须实现Serializable
  • Slower than reflection/Unsafe cloning - 比反射/Unsafe克隆慢
  • Transient fields are not cloned - transient字段不会被克隆

Usage Examples | 使用示例:

SerializingCloner cloner = SerializingCloner.create();
User cloned = cloner.clone(originalUser); // User must be Serializable

Security | 安全性:

  • Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
Since:
JDK 25, opencode-base-deepclone V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • create

      public static SerializingCloner create()
      Creates a SerializingCloner 创建SerializingCloner
      Returns:
      the cloner | 克隆器
    • doClone

      protected <T> T doClone(T original, CloneContext context)
      Description copied from class: AbstractCloner
      Performs the actual cloning logic 执行实际的克隆逻辑
      Specified by:
      doClone in class AbstractCloner
      Type Parameters:
      T - the object type | 对象类型
      Parameters:
      original - the original object | 原始对象
      context - the clone context | 克隆上下文
      Returns:
      the cloned object | 克隆的对象
    • getStrategyName

      public String getStrategyName()
      Description copied from interface: Cloner
      Gets the name of the cloning strategy 获取克隆策略名称
      Returns:
      the strategy name | 策略名称
    • supports

      public boolean supports(Class<?> type)
      Description copied from interface: Cloner
      Checks if this cloner supports the given type 检查此克隆器是否支持给定类型
      Parameters:
      type - the type to check | 要检查的类型
      Returns:
      true if supported | 如果支持返回true