Class CheckerJson
java.lang.Object
util.AbstractChecker<com.fasterxml.jackson.databind.JsonNode,CheckerJson>
specialized_checkers.io.CheckerJson
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<com.fasterxml.jackson.databind.JsonNode,
CheckerJson>, com.fasterxml.jackson.databind.JsonNode>
public class CheckerJson
extends AbstractChecker<com.fasterxml.jackson.databind.JsonNode,CheckerJson>
CheckerJson is a specialized checker for validating properties and structure of JSON data
represented by Jackson's
JsonNode
. It provides a fluent API for asserting the presence,
type, and value constraints of JSON properties, supporting both simple and complex validation scenarios.
This class offers static factory methods to create instances from JsonNode
, File
, or file paths,
with optional custom naming. It includes a variety of assertion methods for checking property existence,
type (e.g., array, object, number, string), value ranges, regular expression matches, and membership in enumerations.
Example usage:
JsonNode json = ...; CheckerJson.check(json) .hasProperty("user.name") .isTextual("user.name") .hasLengthBetween("user.name", 3, 20);
-
Field Summary
Fields inherited from class util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CheckerJson
(com.fasterxml.jackson.databind.JsonNode json, String name) Constructs a newCheckerJson
instance with the specified JSON node and name. -
Method Summary
Modifier and TypeMethodDescriptionstatic CheckerJson
check
(com.fasterxml.jackson.databind.JsonNode json) Creates a CheckerJson for the given JsonNode with a default name.static CheckerJson
Creates a CheckerJson for the given JsonNode and assigns a custom name.static CheckerJson
Creates a CheckerJson from a file with a default name.static CheckerJson
Creates a CheckerJson from a file and assigns a custom name.static CheckerJson
Creates a CheckerJson from a file path with a default name.static CheckerJson
Creates a CheckerJson from a file path and assigns a custom name.hasLengthBetween
(String path, int min, int max) Checks if the length of the textual property at the specified path is within the given range (inclusive).hasProperty
(String path) Checks if the JSON contains the specified property path.Checks if the property at the specified path is an array.isBigDecimal
(String path) Checks if the property at the specified path is a BigDecimal.isBigInteger
(String path) Checks if the property at the specified path is a BigInteger.Checks if the property at the specified path is binary data.Checks if the property at the specified path is a boolean value.isContainerNode
(String path) Checks if the property at the specified path is a container node (object or array).Checks if the property at the specified path is a double value.Checks if the property at the specified path is empty.Checks if the property at the specified path is a float value.isFloatingPointNumber
(String path) Checks if the property at the specified path is a floating point number.Checks if the textual property at the specified path is one of the allowed values.Checks if the integer property at the specified path is within the given range (inclusive).Checks if the property at the specified path is an integer value.isIntegralNumber
(String path) Checks if the property at the specified path is an integral number.Checks if the property at the specified path is a long value.isMissingNode
(String path) Checks if the property at the specified path is a missing node.Checks if the property at the specified path is null.Checks if the property at the specified path is a number.Checks if the property at the specified path is a JSON object.Checks if the property at the specified path is a POJO (Plain Old Java Object).Checks if the property at the specified path is a short value.Checks if the property at the specified path is a textual value (string).matchesRegex
(String path, String regex) Checks if the textual property at the specified path matches the given regular expression.protected CheckerJson
self()
Returns this instance (for fluent API).Methods inherited from class util.AbstractChecker
checkProperty, checkProperty, checkProperty, end, getMethod, getObject, getProperty, hasErrors, hasNotErrors, is, is, isEqual, isNonNull, isNot, isNot, isNull, notSaveErrors, saveErrors, show, showNotThrownException, showThrownException, stop
-
Constructor Details
-
CheckerJson
Constructs a newCheckerJson
instance with the specified JSON node and name.- Parameters:
json
- theJsonNode
containing the configuration or data for this checkername
- the name associated with this checker instance
-
-
Method Details
-
check
Creates a CheckerJson for the given JsonNode and assigns a custom name.- Parameters:
json
- the JsonNode to checkname
- the name to assign to this checker- Returns:
- a CheckerJson instance for the given JsonNode
-
check
Creates a CheckerJson from a file and assigns a custom name.- Parameters:
file
- the file containing JSON dataname
- the name to assign to this checker- Returns:
- a CheckerJson instance for the JSON in the file
- Throws:
IOException
- if the file cannot be read or parsed
-
check
Creates a CheckerJson from a file path and assigns a custom name.- Parameters:
pathname
- the path to the file containing JSON dataname
- the name to assign to this checker- Returns:
- a CheckerJson instance for the JSON in the file
- Throws:
IOException
- if the file cannot be read or parsed
-
check
Creates a CheckerJson for the given JsonNode with a default name.- Parameters:
json
- the JsonNode to check- Returns:
- a CheckerJson instance for the given JsonNode
-
check
Creates a CheckerJson from a file with a default name.- Parameters:
file
- the file containing JSON data- Returns:
- a CheckerJson instance for the JSON in the file
- Throws:
IOException
- if the file cannot be read or parsed
-
check
Creates a CheckerJson from a file path with a default name.- Parameters:
pathname
- the path to the file containing JSON data- Returns:
- a CheckerJson instance for the JSON in the file
- Throws:
IOException
- if the file cannot be read or parsed
-
self
Returns this instance (for fluent API).- Specified by:
self
in classAbstractChecker<com.fasterxml.jackson.databind.JsonNode,
CheckerJson> - Returns:
- this CheckerJson instance
-
hasProperty
Checks if the JSON contains the specified property path.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isArray
Checks if the property at the specified path is an array.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isBigDecimal
Checks if the property at the specified path is a BigDecimal.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isBigInteger
Checks if the property at the specified path is a BigInteger.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isBinary
Checks if the property at the specified path is binary data.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isBoolean
Checks if the property at the specified path is a boolean value.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isContainerNode
Checks if the property at the specified path is a container node (object or array).- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isDouble
Checks if the property at the specified path is a double value.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isEmpty
Checks if the property at the specified path is empty.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isFloat
Checks if the property at the specified path is a float value.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isFloatingPointNumber
Checks if the property at the specified path is a floating point number.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isInt
Checks if the property at the specified path is an integer value.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isIntegralNumber
Checks if the property at the specified path is an integral number.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isLong
Checks if the property at the specified path is a long value.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isMissingNode
Checks if the property at the specified path is a missing node.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isNull
Checks if the property at the specified path is null.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isNumber
Checks if the property at the specified path is a number.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isObject
Checks if the property at the specified path is a JSON object.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isPojo
Checks if the property at the specified path is a POJO (Plain Old Java Object).- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isShort
Checks if the property at the specified path is a short value.- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isTextual
Checks if the property at the specified path is a textual value (string).- Parameters:
path
- the dot-separated path to the property- Returns:
- this CheckerJson instance
-
isInRange
Checks if the integer property at the specified path is within the given range (inclusive).- Parameters:
path
- the dot-separated path to the propertymin
- the minimum valuemax
- the maximum value- Returns:
- this CheckerJson instance
-
matchesRegex
Checks if the textual property at the specified path matches the given regular expression.- Parameters:
path
- the dot-separated path to the propertyregex
- the regular expression to match- Returns:
- this CheckerJson instance
-
isInEnum
Checks if the textual property at the specified path is one of the allowed values.- Parameters:
path
- the dot-separated path to the propertyallowedValues
- the list of allowed string values- Returns:
- this CheckerJson instance
-
hasLengthBetween
Checks if the length of the textual property at the specified path is within the given range (inclusive).- Parameters:
path
- the dot-separated path to the propertymin
- the minimum lengthmax
- the maximum length- Returns:
- this CheckerJson instance
-