Enum PathType

java.lang.Object
java.lang.Enum<PathType>
com.networknt.schema.PathType
All Implemented Interfaces:
Serializable, Comparable<PathType>, java.lang.constant.Constable

public enum PathType extends Enum<PathType>
Enumeration defining the different approached available to generate the paths added to validation messages.
  • Enum Constant Details

    • LEGACY

      public static final PathType LEGACY
      The legacy approach, loosely based on JSONPath (but not guaranteed to give valid JSONPath expressions).
    • JSON_PATH

      public static final PathType JSON_PATH
      Paths as JSONPath expressions.
    • JSON_POINTER

      public static final PathType JSON_POINTER
      Paths as JSONPointer expressions.
    • URI_REFERENCE

      public static final PathType URI_REFERENCE
      Paths as a URI reference.
  • Field Details

  • Constructor Details

    • PathType

      private PathType(String rootToken, BiFunction<String,String,String> appendTokenFn, BiFunction<String,Integer,String> appendIndexFn)
      Constructor.
      Parameters:
      rootToken - The token representing the document root.
      appendTokenFn - A function used to define the path fragment used to append a token (e.g. property) to an existing path.
      appendIndexFn - A function used to append an index (for arrays) to an existing path.
  • Method Details

    • values

      public static PathType[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static PathType valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • replaceCommonSpecialCharactersIfPresent

      private static String replaceCommonSpecialCharactersIfPresent(String token)
      Replace common special characters that are to be considered for all types of paths.
      Parameters:
      token - The path token (property name or selector).
      Returns:
      The token to use in the path.
    • append

      public String append(String currentPath, String child)
      Append the given child token to the provided current path.
      Parameters:
      currentPath - The path to append to.
      child - The child token.
      Returns:
      The resulting complete path.
    • append

      public String append(String currentPath, int index)
      Append the given index to the provided current path.
      Parameters:
      currentPath - The path to append to.
      index - The index to append.
      Returns:
      The resulting complete path.
    • getRoot

      public String getRoot()
      Return the representation of the document root.
      Returns:
      The root token.
    • convertToJsonPointer

      public String convertToJsonPointer(String path)
    • fromLegacy

      static String fromLegacy(String path)
    • fromJsonPath

      static String fromJsonPath(String str)
    • parseShorthand

      static int parseShorthand(StringBuilder sb, String s, int pos)
      Parses a JSONPath shorthand selector
      Parameters:
      sb - receives the result
      s - the source string
      pos - the index into s immediately following the dot
      Returns:
      the index following the selector name
    • parseSelector

      static int parseSelector(StringBuilder sb, String s, int pos)
      Parses a JSONPath selector
      Parameters:
      sb - receives the result
      s - the source string
      pos - the index into s immediately following the open bracket
      Returns:
      the index following the closing bracket
    • parseQuote

      static int parseQuote(StringBuilder sb, String s, int pos)
      Parses a single-quoted string.
      Parameters:
      sb - receives the result
      s - the source string
      pos - the index into s immediately following the open quote
      Returns:
      the index following the closing quote