Class OpenSerializationException

All Implemented Interfaces:
Serializable

public class OpenSerializationException extends OpenException
OpenSerializationException - Serialization Exception 序列化异常

Exception thrown when serialization or deserialization operations fail.

当序列化或反序列化操作失败时抛出的异常。

Features | 主要功能:

  • Serialize failure handling - 序列化失败处理
  • Deserialize failure handling - 反序列化失败处理
  • Serializer not found handling - 序列化器未找到处理
  • Unsupported type handling - 不支持的类型处理
  • Compression/Decompression failure handling - 压缩/解压失败处理

Usage Examples | 使用示例:

throw OpenSerializationException.serializeFailed(obj, cause);
throw OpenSerializationException.deserializeFailed(data, type, cause);
throw OpenSerializationException.serializerNotFound("msgpack");

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是 (不可变)
  • Serializable: Yes - 可序列化: 是
Since:
JDK 25, opencode-base-serialization V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenSerializationException

      public OpenSerializationException(String message)
      Creates a serialization exception with message. 创建带消息的序列化异常。
      Parameters:
      message - the error message - 错误消息
    • OpenSerializationException

      public OpenSerializationException(String message, Throwable cause)
      Creates a serialization exception with message and cause. 创建带消息和原因的序列化异常。
      Parameters:
      message - the error message - 错误消息
      cause - the cause - 原因
    • OpenSerializationException

      public OpenSerializationException(String message, String format, Class<?> targetType, Throwable cause)
      Creates a serialization exception with full details. 创建带完整详情的序列化异常。
      Parameters:
      message - the error message - 错误消息
      format - the serialization format - 序列化格式
      targetType - the target type - 目标类型
      cause - the cause - 原因
  • Method Details

    • getFormat

      public String getFormat()
      Returns the serialization format. 返回序列化格式。
      Returns:
      the format, may be null - 格式,可能为 null
    • getTargetType

      public Class<?> getTargetType()
      Returns the target type. 返回目标类型。
      Returns:
      the target type, may be null - 目标类型,可能为 null
    • serializeFailed

      public static OpenSerializationException serializeFailed(Object obj, Throwable cause)
      Creates exception for serialization failure. 创建序列化失败异常。
      Parameters:
      obj - the object that failed to serialize - 序列化失败的对象
      cause - the cause - 原因
      Returns:
      the exception - 异常
    • serializeFailed

      public static OpenSerializationException serializeFailed(Object obj, String format, Throwable cause)
      Creates exception for serialization failure with format. 创建带格式的序列化失败异常。
      Parameters:
      obj - the object that failed to serialize - 序列化失败的对象
      format - the serialization format - 序列化格式
      cause - the cause - 原因
      Returns:
      the exception - 异常
    • deserializeFailed

      public static OpenSerializationException deserializeFailed(byte[] data, Class<?> type, Throwable cause)
      Creates exception for deserialization failure. 创建反序列化失败异常。
      Parameters:
      data - the data that failed to deserialize - 反序列化失败的数据
      type - the target type - 目标类型
      cause - the cause - 原因
      Returns:
      the exception - 异常
    • deserializeFailed

      public static OpenSerializationException deserializeFailed(byte[] data, Class<?> type, String format, Throwable cause)
      Creates exception for deserialization failure with format. 创建带格式的反序列化失败异常。
      Parameters:
      data - the data that failed to deserialize - 反序列化失败的数据
      type - the target type - 目标类型
      format - the serialization format - 序列化格式
      cause - the cause - 原因
      Returns:
      the exception - 异常
    • serializerNotFound

      public static OpenSerializationException serializerNotFound(String format)
      Creates exception when serializer is not found. 创建序列化器未找到异常。
      Parameters:
      format - the requested format - 请求的格式
      Returns:
      the exception - 异常
    • unsupportedType

      public static OpenSerializationException unsupportedType(Type type, String format)
      Creates exception for unsupported type. 创建不支持类型异常。
      Parameters:
      type - the unsupported type - 不支持的类型
      format - the serialization format - 序列化格式
      Returns:
      the exception - 异常
    • unsupportedType

      public static OpenSerializationException unsupportedType(Class<?> type, String format)
      Creates exception for unsupported type. 创建不支持类型异常。
      Parameters:
      type - the unsupported type - 不支持的类型
      format - the serialization format - 序列化格式
      Returns:
      the exception - 异常
    • compressionFailed

      public static OpenSerializationException compressionFailed(Throwable cause)
      Creates exception for compression failure. 创建压缩失败异常。
      Parameters:
      cause - the cause - 原因
      Returns:
      the exception - 异常
    • compressionFailed

      public static OpenSerializationException compressionFailed(String algorithm, Throwable cause)
      Creates exception for compression failure with algorithm. 创建带算法的压缩失败异常。
      Parameters:
      algorithm - the compression algorithm - 压缩算法
      cause - the cause - 原因
      Returns:
      the exception - 异常
    • decompressionFailed

      public static OpenSerializationException decompressionFailed(Throwable cause)
      Creates exception for decompression failure. 创建解压失败异常。
      Parameters:
      cause - the cause - 原因
      Returns:
      the exception - 异常
    • decompressionFailed

      public static OpenSerializationException decompressionFailed(String algorithm, Throwable cause)
      Creates exception for decompression failure with algorithm. 创建带算法的解压失败异常。
      Parameters:
      algorithm - the compression algorithm - 压缩算法
      cause - the cause - 原因
      Returns:
      the exception - 异常
    • missingDependency

      public static OpenSerializationException missingDependency(String format, String dependency)
      Creates exception for missing dependency. 创建缺少依赖异常。
      Parameters:
      format - the format requiring the dependency - 需要依赖的格式
      dependency - the missing dependency - 缺少的依赖
      Returns:
      the exception - 异常