Class OpenJsonProcessingException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.core.exception.OpenException
cloud.opencode.base.json.exception.OpenJsonProcessingException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
JsonSchemaException
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
OpenExceptionwith 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumError type enumeration 错误类型枚举 -
Constructor Summary
ConstructorsConstructorDescriptionOpenJsonProcessingException(String message) Constructs a new exception with the specified message.OpenJsonProcessingException(String message, OpenJsonProcessingException.ErrorType errorType) Constructs a new exception with the specified message and error type.OpenJsonProcessingException(String message, OpenJsonProcessingException.ErrorType errorType, Throwable cause) Constructs a new exception with the specified message, error type, and cause.OpenJsonProcessingException(String message, OpenJsonProcessingException.ErrorType errorType, Throwable cause, int line, int column, String source) Constructs a new exception with full location information.OpenJsonProcessingException(String message, Throwable cause) Constructs a new exception with the specified message and cause. -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenJsonProcessingExceptionconfigError(String message) Creates a configuration error exception.static OpenJsonProcessingExceptiondeserializationError(String message, Throwable cause) Creates a deserialization error exception.intReturns the column number where the error occurred.Returns the error type.intgetLine()Returns the line number where the error occurred.Returns a formatted location string.Returns the raw message without component/error-code prefix or location suffix.Returns the source identifier.booleanReturns whether location information is available.static OpenJsonProcessingExceptionCreates an IO error exception.static OpenJsonProcessingExceptionparseError(String message) Creates a parse error exception.static OpenJsonProcessingExceptionparseError(String message, int line, int column) Creates a parse error exception with location.static OpenJsonProcessingExceptionCreates a path evaluation error exception.static OpenJsonProcessingExceptionserializationError(String message, Throwable cause) Creates a serialization error exception.static OpenJsonProcessingExceptiontypeConversionError(String message) Creates a type conversion error exception.Methods inherited from class OpenException
getComponent, getErrorCodeMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
OpenJsonProcessingException
Constructs a new exception with the specified message. 使用指定消息构造新异常。- Parameters:
message- the detail message - 详细消息
-
OpenJsonProcessingException
-
OpenJsonProcessingException
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
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
Returns a formatted location string. 返回格式化的位置字符串。- Returns:
- the location string - 位置字符串
-
getMessage
- Overrides:
getMessagein classOpenException
-
getRawMessage
Returns the raw message without component/error-code prefix or location suffix. 返回不含组件/错误码前缀和位置后缀的原始消息。- Overrides:
getRawMessagein classOpenException- Returns:
- the raw message - 原始消息
-
parseError
Creates a parse error exception. 创建解析错误异常。- Parameters:
message- the detail message - 详细消息- Returns:
- the exception - 异常
-
parseError
Creates a parse error exception with location. 创建带位置信息的解析错误异常。- Parameters:
message- the detail message - 详细消息line- the line number - 行号column- the column number - 列号- Returns:
- the exception - 异常
-
serializationError
Creates a serialization error exception. 创建序列化错误异常。- Parameters:
message- the detail message - 详细消息cause- the cause - 原因- Returns:
- the exception - 异常
-
deserializationError
Creates a deserialization error exception. 创建反序列化错误异常。- Parameters:
message- the detail message - 详细消息cause- the cause - 原因- Returns:
- the exception - 异常
-
typeConversionError
Creates a type conversion error exception. 创建类型转换错误异常。- Parameters:
message- the detail message - 详细消息- Returns:
- the exception - 异常
-
pathError
Creates a path evaluation error exception. 创建路径求值错误异常。- Parameters:
message- the detail message - 详细消息- Returns:
- the exception - 异常
-
ioError
Creates an IO error exception. 创建IO错误异常。- Parameters:
message- the detail message - 详细消息cause- the cause - 原因- Returns:
- the exception - 异常
-
configError
Creates a configuration error exception. 创建配置错误异常。- Parameters:
message- the detail message - 详细消息- Returns:
- the exception - 异常
-