Enum PathType

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<PathType>

    public enum PathType
    extends java.lang.Enum<PathType>
    Enumeration defining the different approached available to generate the paths added to validation messages.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  PathType.JSONPath  
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      JSON_PATH
      Paths as JSONPath expressions.
      JSON_POINTER
      Paths as JSONPointer expressions.
      LEGACY
      The legacy approach, loosely based on JSONPath (but not guaranteed to give valid JSONPath expressions).
      URI_REFERENCE
      Paths as a URI reference.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.function.BiFunction<java.lang.String,​java.lang.Integer,​java.lang.String> appendIndexFn  
      private java.util.function.BiFunction<java.lang.String,​java.lang.String,​java.lang.String> appendTokenFn  
      static PathType DEFAULT
      The default path generation approach to use.
      private java.lang.String rootToken  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private PathType​(java.lang.String rootToken, java.util.function.BiFunction<java.lang.String,​java.lang.String,​java.lang.String> appendTokenFn, java.util.function.BiFunction<java.lang.String,​java.lang.Integer,​java.lang.String> appendIndexFn)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String append​(java.lang.String currentPath, int index)
      Append the given index to the provided current path.
      java.lang.String append​(java.lang.String currentPath, java.lang.String child)
      Append the given child token to the provided current path.
      java.lang.String convertToJsonPointer​(java.lang.String path)  
      (package private) static java.lang.String fromJsonPath​(java.lang.String str)  
      (package private) static java.lang.String fromLegacy​(java.lang.String path)  
      java.lang.String getRoot()
      Return the representation of the document root.
      (package private) static int parseQuote​(java.lang.StringBuilder sb, java.lang.String s, int pos)
      Parses a single-quoted string.
      (package private) static int parseSelector​(java.lang.StringBuilder sb, java.lang.String s, int pos)
      Parses a JSONPath selector
      (package private) static int parseShorthand​(java.lang.StringBuilder sb, java.lang.String s, int pos)
      Parses a JSONPath shorthand selector
      private static java.lang.String replaceCommonSpecialCharactersIfPresent​(java.lang.String token)
      Replace common special characters that are to be considered for all types of paths.
      static PathType valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static PathType[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • 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 Detail

      • DEFAULT

        public static final PathType DEFAULT
        The default path generation approach to use.
      • rootToken

        private final java.lang.String rootToken
      • appendTokenFn

        private final java.util.function.BiFunction<java.lang.String,​java.lang.String,​java.lang.String> appendTokenFn
      • appendIndexFn

        private final java.util.function.BiFunction<java.lang.String,​java.lang.Integer,​java.lang.String> appendIndexFn
    • Constructor Detail

      • PathType

        private PathType​(java.lang.String rootToken,
                         java.util.function.BiFunction<java.lang.String,​java.lang.String,​java.lang.String> appendTokenFn,
                         java.util.function.BiFunction<java.lang.String,​java.lang.Integer,​java.lang.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 Detail

      • values

        public static PathType[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (PathType c : PathType.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static PathType valueOf​(java.lang.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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • replaceCommonSpecialCharactersIfPresent

        private static java.lang.String replaceCommonSpecialCharactersIfPresent​(java.lang.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 java.lang.String append​(java.lang.String currentPath,
                                       java.lang.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 java.lang.String append​(java.lang.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 java.lang.String getRoot()
        Return the representation of the document root.
        Returns:
        The root token.
      • convertToJsonPointer

        public java.lang.String convertToJsonPointer​(java.lang.String path)
      • fromLegacy

        static java.lang.String fromLegacy​(java.lang.String path)
      • fromJsonPath

        static java.lang.String fromJsonPath​(java.lang.String str)
      • parseShorthand

        static int parseShorthand​(java.lang.StringBuilder sb,
                                  java.lang.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​(java.lang.StringBuilder sb,
                                 java.lang.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​(java.lang.StringBuilder sb,
                              java.lang.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