public interface JsSpec
JSON specifications are essential for parsing and validating JSON data in applications, ensuring that the data adheres to predefined rules before processing or storing it.
Implementations of this interface define custom validation rules and provide methods for testing JSON values against these rules. The primary goal is to verify whether a given JSON value satisfies the specification.
The `JsSpec` interface offers the following key functionality: - Enabling the nullable flag, indicating whether the JSON value can be null. - Retrieving the deserializer used during the parsing process for parsing arrays of bytes or strings into JSON values. - Reading and parsing JSON values token by token from a reader while verifying if they conform to the specification. - Testing JSON values against the specification and returning a set of path/error pairs for validation errors.
This interface serves as a foundation for building a JSON validation framework and allows for the creation of custom JSON specifications for various data types, including numbers, strings, arrays, objects, and more.
Implementations of this interface should be immutable and thread-safe to support concurrent usage.
Modifier and Type | Method and Description |
---|---|
JsSpec |
nullable()
Returns the same spec with the nullable flag enabled.
|
jsonvalues.spec.JsSpecParser |
parser()
Returns the deserializer used during the parsing process to parse an array of bytes or strings
into a JSON value.
|
default JsValue |
readNextValue(JsReader reader)
Low-level method to parse a JSON value token by token from a reader.
|
Set<SpecError> |
test(JsPath parentPath,
JsValue value)
Verify if the given JSON value satisfies this spec.
|
default Set<SpecError> |
test(JsValue value)
Verify if the given JSON value satisfies this spec, starting from the root path.
|
JsSpec nullable()
jsonvalues.spec.JsSpecParser parser()
default JsValue readNextValue(JsReader reader) throws JsParserException
reader
- The reader to parse JSON values from.JsParserException
- If the parsed value does not conform to this spec.Set<SpecError> test(JsPath parentPath, JsValue value)
parentPath
- The path where the tested value is located within the JSON structure.value
- The JSON value to be tested.Copyright © 2023. All rights reserved.