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);
 
  • Constructor Details

    • CheckerJson

      protected CheckerJson(com.fasterxml.jackson.databind.JsonNode json, String name)
      Constructs a new CheckerJson instance with the specified JSON node and name.
      Parameters:
      json - the JsonNode containing the configuration or data for this checker
      name - the name associated with this checker instance
  • Method Details

    • check

      public static CheckerJson check(com.fasterxml.jackson.databind.JsonNode json, String name)
      Creates a CheckerJson for the given JsonNode and assigns a custom name.
      Parameters:
      json - the JsonNode to check
      name - the name to assign to this checker
      Returns:
      a CheckerJson instance for the given JsonNode
    • check

      public static CheckerJson check(File file, String name) throws IOException
      Creates a CheckerJson from a file and assigns a custom name.
      Parameters:
      file - the file containing JSON data
      name - 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

      public static CheckerJson check(String pathname, String name) throws IOException
      Creates a CheckerJson from a file path and assigns a custom name.
      Parameters:
      pathname - the path to the file containing JSON data
      name - 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

      public static CheckerJson check(com.fasterxml.jackson.databind.JsonNode json)
      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

      public static CheckerJson check(File file) throws IOException
      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

      public static CheckerJson check(String pathname) throws IOException
      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

      protected CheckerJson self()
      Returns this instance (for fluent API).
      Specified by:
      self in class AbstractChecker<com.fasterxml.jackson.databind.JsonNode,CheckerJson>
      Returns:
      this CheckerJson instance
    • hasProperty

      public CheckerJson hasProperty(String path)
      Checks if the JSON contains the specified property path.
      Parameters:
      path - the dot-separated path to the property
      Returns:
      this CheckerJson instance
    • isArray

      public CheckerJson isArray(String path)
      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

      public CheckerJson isBigDecimal(String path)
      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

      public CheckerJson isBigInteger(String path)
      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

      public CheckerJson isBinary(String path)
      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

      public CheckerJson isBoolean(String path)
      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

      public CheckerJson isContainerNode(String path)
      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

      public CheckerJson isDouble(String path)
      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

      public CheckerJson isEmpty(String path)
      Checks if the property at the specified path is empty.
      Parameters:
      path - the dot-separated path to the property
      Returns:
      this CheckerJson instance
    • isFloat

      public CheckerJson isFloat(String path)
      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

      public CheckerJson isFloatingPointNumber(String path)
      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

      public CheckerJson isInt(String path)
      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

      public CheckerJson isIntegralNumber(String path)
      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

      public CheckerJson isLong(String path)
      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

      public CheckerJson isMissingNode(String path)
      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

      public CheckerJson isNull(String path)
      Checks if the property at the specified path is null.
      Parameters:
      path - the dot-separated path to the property
      Returns:
      this CheckerJson instance
    • isNumber

      public CheckerJson isNumber(String path)
      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

      public CheckerJson isObject(String path)
      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

      public CheckerJson isPojo(String path)
      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

      public CheckerJson isShort(String path)
      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

      public CheckerJson isTextual(String path)
      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

      public CheckerJson isInRange(String path, int min, int max)
      Checks if the integer property at the specified path is within the given range (inclusive).
      Parameters:
      path - the dot-separated path to the property
      min - the minimum value
      max - the maximum value
      Returns:
      this CheckerJson instance
    • matchesRegex

      public CheckerJson matchesRegex(String path, String regex)
      Checks if the textual property at the specified path matches the given regular expression.
      Parameters:
      path - the dot-separated path to the property
      regex - the regular expression to match
      Returns:
      this CheckerJson instance
    • isInEnum

      public CheckerJson isInEnum(String path, List<String> allowedValues)
      Checks if the textual property at the specified path is one of the allowed values.
      Parameters:
      path - the dot-separated path to the property
      allowedValues - the list of allowed string values
      Returns:
      this CheckerJson instance
    • hasLengthBetween

      public CheckerJson 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).
      Parameters:
      path - the dot-separated path to the property
      min - the minimum length
      max - the maximum length
      Returns:
      this CheckerJson instance