Class JsonSchemaException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.core.exception.OpenException
cloud.opencode.base.json.exception.OpenJsonProcessingException
cloud.opencode.base.json.exception.JsonSchemaException
- All Implemented Interfaces:
Serializable
JSON Schema Exception - Exception for Schema Validation Failures
JSON Schema 异常 - Schema 验证失败异常
This exception is thrown when JSON Schema validation fails. It contains detailed information about all validation errors encountered.
当 JSON Schema 验证失败时抛出此异常。它包含遇到的所有验证错误的详细信息。
Example | 示例:
try {
JsonSchemaValidator.validate(json, schema);
} catch (JsonSchemaException e) {
for (ValidationError error : e.getErrors()) {
System.err.println(error.getPath() + ": " + error.getMessage());
}
}
Features | 主要功能:
- Detailed validation error information - 详细的验证错误信息
- Multiple error collection and reporting - 多错误收集和报告
- Builder pattern for constructing complex validation exceptions - 构建复杂验证异常的构建器模式
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
- Since:
- JDK 25, opencode-base-json V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating exceptions with multiple errors.static final recordValidation Error - Represents a Single Schema Validation Error 验证错误 - 表示单个 Schema 验证错误Nested classes/interfaces inherited from class OpenJsonProcessingException
OpenJsonProcessingException.ErrorType -
Constructor Summary
ConstructorsConstructorDescriptionJsonSchemaException(String message) Constructs a new exception with a single error message.JsonSchemaException(String message, List<JsonSchemaException.ValidationError> errors) Constructs a new exception with validation errors.JsonSchemaException(String message, List<JsonSchemaException.ValidationError> errors, String schemaUri) Constructs a new exception with validation errors and schema URI. -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonSchemaException.Builderbuilder()Creates a new builder.static JsonSchemaExceptionconstraintViolation(String path, String constraint, String message) Creates an exception for a constraint violation error.intReturns the number of validation errors.Returns a formatted error report.Returns the list of validation errors.Returns the schema URI that was validated against.booleanReturns whether there are any errors.static JsonSchemaExceptionmissingRequired(String path, String property) Creates an exception for a required property error.static JsonSchemaExceptionpatternMismatch(String path, String pattern, String value) Creates an exception for a pattern mismatch error.static JsonSchemaExceptiontypeMismatch(String path, String expected, String actual) Creates an exception for a type mismatch error.Methods inherited from class OpenJsonProcessingException
configError, deserializationError, getColumn, getErrorType, getLine, getLocationString, getRawMessage, getSource, hasLocation, ioError, parseError, parseError, pathError, serializationError, typeConversionErrorMethods inherited from class OpenException
getComponent, getErrorCodeMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
JsonSchemaException
Constructs a new exception with a single error message. 使用单个错误消息构造新异常。- Parameters:
message- the detail message - 详细消息
-
JsonSchemaException
Constructs a new exception with validation errors. 使用验证错误列表构造新异常。- Parameters:
message- the detail message - 详细消息errors- the validation errors - 验证错误列表
-
JsonSchemaException
public JsonSchemaException(String message, List<JsonSchemaException.ValidationError> errors, String schemaUri) Constructs a new exception with validation errors and schema URI. 使用验证错误列表和 Schema URI 构造新异常。- Parameters:
message- the detail message - 详细消息errors- the validation errors - 验证错误列表schemaUri- the schema URI - Schema URI
-
-
Method Details
-
getErrors
Returns the list of validation errors. 返回验证错误列表。- Returns:
- unmodifiable list of validation errors - 不可变的验证错误列表
-
getErrorCount
public int getErrorCount()Returns the number of validation errors. 返回验证错误数量。- Returns:
- the error count - 错误数量
-
getSchemaUri
Returns the schema URI that was validated against. 返回验证所使用的 Schema URI。- Returns:
- the schema URI, or null if not specified - Schema URI,未指定时返回 null
-
hasErrors
public boolean hasErrors()Returns whether there are any errors. 返回是否存在错误。- Returns:
- true if there are errors - 如果存在错误则返回 true
-
getErrorReport
Returns a formatted error report. 返回格式化的错误报告。- Returns:
- the error report - 错误报告
-
getMessage
- Overrides:
getMessagein classOpenJsonProcessingException
-
typeMismatch
Creates an exception for a type mismatch error. 创建类型不匹配错误的异常。- Parameters:
path- the JSON path - JSON 路径expected- the expected type - 预期类型actual- the actual type - 实际类型- Returns:
- the exception - 异常
-
missingRequired
Creates an exception for a required property error. 创建必需属性错误的异常。- Parameters:
path- the JSON path - JSON 路径property- the missing property name - 缺失的属性名- Returns:
- the exception - 异常
-
patternMismatch
Creates an exception for a pattern mismatch error. 创建模式不匹配错误的异常。- Parameters:
path- the JSON path - JSON 路径pattern- the expected pattern - 预期模式value- the actual value - 实际值- Returns:
- the exception - 异常
-
constraintViolation
public static JsonSchemaException constraintViolation(String path, String constraint, String message) Creates an exception for a constraint violation error. 创建约束违反错误的异常。- Parameters:
path- the JSON path - JSON 路径constraint- the constraint keyword - 约束关键字message- the error message - 错误消息- Returns:
- the exception - 异常
-
builder
Creates a new builder. 创建新的构建器。- Returns:
- a new builder - 新构建器
-