Class OpenJsonProcessingException

All Implemented Interfaces:
OpenExceptionMeta, Serializable
Direct Known Subclasses:
JsonSchemaException

public class OpenJsonProcessingException extends OpenException
JSON Processing Exception - Base Exception for JSON Operations JSON 处理异常 - JSON 操作的基础异常

This exception is thrown when JSON serialization, deserialization, or other JSON processing operations fail.

当 JSON 序列化、反序列化或其他 JSON 处理操作失败时抛出此异常。

Example | 示例:

try {
    Object result = OpenJson.parse(invalidJson);
} catch (OpenJsonProcessingException e) {
    System.err.println("JSON error at line " + e.getLine() +
                       ", column " + e.getColumn());
}

Features | 主要功能:

  • Categorized error types (parse, serialization, deserialization, etc.) - 分类错误类型
  • Optional error location (line, column) tracking - 可选的错误位置(行、列)跟踪
  • Factory methods for common error scenarios - 常见错误场景的工厂方法
  • Extends OpenException with component="json" - 继承 OpenException,组件名="json"

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
  • Null-safe: N/A - 空值安全: 不适用
Since:
JDK 25, opencode-base-json V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenJsonProcessingException

      public OpenJsonProcessingException(String message)
      Constructs a new exception with the specified message. 使用指定消息构造新异常。
      Parameters:
      message - the detail message - 详细消息
    • OpenJsonProcessingException

      public OpenJsonProcessingException(String message, Throwable cause)
      Constructs a new exception with the specified message and cause. 使用指定消息和原因构造新异常。
      Parameters:
      message - the detail message - 详细消息
      cause - the cause - 原因
    • OpenJsonProcessingException

      public OpenJsonProcessingException(String message, OpenJsonProcessingException.ErrorType errorType)
      Constructs a new exception with the specified message and error type. 使用指定消息和错误类型构造新异常。
      Parameters:
      message - the detail message - 详细消息
      errorType - the error type - 错误类型
    • OpenJsonProcessingException

      public OpenJsonProcessingException(String message, OpenJsonProcessingException.ErrorType errorType, Throwable cause)
      Constructs a new exception with the specified message, error type, and cause. 使用指定消息、错误类型和原因构造新异常。
      Parameters:
      message - the detail message - 详细消息
      errorType - the error type - 错误类型
      cause - the cause - 原因
    • OpenJsonProcessingException

      public OpenJsonProcessingException(String message, OpenJsonProcessingException.ErrorType errorType, Throwable cause, int line, int column, String source)
      Constructs a new exception with full location information. 使用完整位置信息构造新异常。
      Parameters:
      message - the detail message - 详细消息
      errorType - the error type - 错误类型
      cause - the cause - 原因
      line - the line number - 行号
      column - the column number - 列号
      source - the source identifier - 源标识符
  • Method Details

    • getErrorType

      Returns the error type. 返回错误类型。
      Returns:
      the error type - 错误类型
    • getLine

      public int getLine()
      Returns the line number where the error occurred. 返回发生错误的行号。
      Returns:
      the line number, or -1 if unknown - 行号,未知时返回-1
    • getColumn

      public int getColumn()
      Returns the column number where the error occurred. 返回发生错误的列号。
      Returns:
      the column number, or -1 if unknown - 列号,未知时返回-1
    • getSource

      public String getSource()
      Returns the source identifier. 返回源标识符。
      Returns:
      the source, or null if unknown - 源标识符,未知时返回null
    • hasLocation

      public boolean hasLocation()
      Returns whether location information is available. 返回位置信息是否可用。
      Returns:
      true if line and column are known - 如果行号和列号已知则返回true
    • getLocationString

      public String getLocationString()
      Returns a formatted location string. 返回格式化的位置字符串。
      Returns:
      the location string - 位置字符串
    • getMessage

      public String getMessage()
      Overrides:
      getMessage in class OpenException
    • getRawMessage

      public String getRawMessage()
      Returns the raw message without component/error-code prefix or location suffix. 返回不含组件/错误码前缀和位置后缀的原始消息。
      Overrides:
      getRawMessage in class OpenException
      Returns:
      the raw message - 原始消息
    • parseError

      public static OpenJsonProcessingException parseError(String message)
      Creates a parse error exception. 创建解析错误异常。
      Parameters:
      message - the detail message - 详细消息
      Returns:
      the exception - 异常
    • parseError

      public static OpenJsonProcessingException parseError(String message, int line, int column)
      Creates a parse error exception with location. 创建带位置信息的解析错误异常。
      Parameters:
      message - the detail message - 详细消息
      line - the line number - 行号
      column - the column number - 列号
      Returns:
      the exception - 异常
    • serializationError

      public static OpenJsonProcessingException serializationError(String message, Throwable cause)
      Creates a serialization error exception. 创建序列化错误异常。
      Parameters:
      message - the detail message - 详细消息
      cause - the cause - 原因
      Returns:
      the exception - 异常
    • deserializationError

      public static OpenJsonProcessingException deserializationError(String message, Throwable cause)
      Creates a deserialization error exception. 创建反序列化错误异常。
      Parameters:
      message - the detail message - 详细消息
      cause - the cause - 原因
      Returns:
      the exception - 异常
    • typeConversionError

      public static OpenJsonProcessingException typeConversionError(String message)
      Creates a type conversion error exception. 创建类型转换错误异常。
      Parameters:
      message - the detail message - 详细消息
      Returns:
      the exception - 异常
    • pathError

      public static OpenJsonProcessingException pathError(String message)
      Creates a path evaluation error exception. 创建路径求值错误异常。
      Parameters:
      message - the detail message - 详细消息
      Returns:
      the exception - 异常
    • ioError

      public static OpenJsonProcessingException ioError(String message, Throwable cause)
      Creates an IO error exception. 创建IO错误异常。
      Parameters:
      message - the detail message - 详细消息
      cause - the cause - 原因
      Returns:
      the exception - 异常
    • configError

      public static OpenJsonProcessingException configError(String message)
      Creates a configuration error exception. 创建配置错误异常。
      Parameters:
      message - the detail message - 详细消息
      Returns:
      the exception - 异常