Class ReadArrJSON.DimN

  • Enclosing class:
    ReadArrJSON

    public static class ReadArrJSON.DimN
    extends java.lang.Object
    JSON Binding Helper-Class:
    JSON-Binding is the art of converting data that has been stored, saved or transmitted using Java-Script Object Notation into a Primitive-Type or Object-Type of any Programming Language, for instance Java. JSON often arrives into Java-Program Memory from an external Internet Connection, and may have traveled hundreds or even thousands of miles from a Host-Server.

    Unlike Java-Types which are checked by the Java-Compiler each-and-every time a programmer compiles his project, any guarantee that JSON-Type Data is pristine, uncorrupted, and in any kind of pre-agreed format is never completely assured.

    Being able to handle changes that might be made to an API (possibly from great distances away, and without the Software-Manager's consent) is the type of feature that robust JSON-Code simply has to offer.

    Binding-Helper Features:
    • Utilizes the Java-Standard javax.json.* Package-Library, & its Glass-Fish Implementation
    • Handles the Transfer & Conversion of All Json-Type's into Java-Type's with just One Line of Code
    • Provides all manner of User-Configurable Exception-Handling & Error-Decision Management via Class JFlag
    • Provides a Fine-Grained Suite of Exception-Classes, all with Consistent & Meaningful Error-Messages
    • Primary Helper-Classes for the (Experimental) Google-Chrome Headless Browser Package
    Parses Multi-Dimensional JSON Array's into Multi-Dimensional Java Array's.

    This class builds on the J2EE Standard 'Glass-Fish' JSON Processor

    There are several JSON Parsers available, and even more implementations for serializing and de-serializing data to/from JSON. The tool included in the J2EE is available on GitHub, and that is the one used by the Java HTML JAR Library. (See: javax.json.* )

    Primary Classes Used: JsonArray and JsonObject

    The class allows a user to extract any Java array-type (including Primitive-Arrays) having any number of dimensions for the array, from a JsonArray.


    JSON-Array Types:
    JsonArray's are allowed quite a bit of leeway in how their data is arranged. First, a JsonArray isn't required to contain a single type of data object. An array may have a JsonString followed by three JsonNumber's, and end with another JsonArray. Java does not allow such array types.

    In Java, for instance, a two-dimensional String-Array may only have actual String-references in the second-dimensional arrays! The first-dimension of the array must contain String[] array pointers, or nulls. A JsonArray could contain several String's follwed by another, nested, JsonArray of String's. Care must be taken in how to handle such parses so that the data is parsed properly, and that the output would adhere to standard Java Array-Type "rules" (for lack of a better term).

    Here is an example that is perfectly legal in JSON, but simply may not be parsed into any correlated-array in Java. Attempting to use this multi-dimensional array parser on the following JsonArray will cause an exception throw.

    Java Script Object Notation (JSON):
    {
        "MyValidJsonArray": [ "Hello", "How are You?", ["This", "is", "not", "allowed", "in Java"]]
    }
    


    The above example will cause an exception throw if attempting to convert it into a Two-Dimensional String[]-Array. In Java, the first dimension of the array may only contain sub-arrays of type String[]. It is the Second-Dimension that may actually have String-References.

    Parsing the above JsonArray would require the programmer to first decide how he wishes to represent the array, and then essentially write a manual conversion algorithm to generate some version of what is above. In leiu of "guessing" what the programmer actually wants done, this type of JsonArray simply cannot be type-transformer class.


    IMPORTANT:
    In each of the methods in this class, the programmer must provide the return-type that should be returned by that method. The java.lang.Class provided must obey the following specifications:

    • The return-type must be an array-type class
    • The root component-class of the array must be consistent with the method-name
    • The dimensionality of the array must be equal to the variable, field or parameter to which the method result is being assigned.

    For instance, to parse a three-dimensional String-Array, one would use the following line of code. Note that the appropriate class is simply obtained by appending '.class' to the end of the String-array. Also note that the variable being assigned (myStrArray) has an identical-type to the type-class passed to this method (String[][]).

    Java Line of Code:
    String[][] myStrArray = ReadArrJSON.DimN.strArr(someJsonArray, null, 0, String[][].class);
    
    See Also:
    Json, JsonArray



    Stateless Class:
    This class neither contains any program-state, nor can it be instantiated. The @StaticFunctional Annotation may also be called 'The Spaghetti Report'. Static-Functional classes are, essentially, C-Styled Files, without any constructors or non-static member fields. It is a concept very similar to the Java-Bean's @Stateless Annotation.

    • 1 Constructor(s), 1 declared private, zero-argument constructor
    • 20 Method(s), 20 declared static
    • 0 Field(s)


    • Method Summary

       
      Read a JsonArray into a Multi-Dimensional Object-Array
      Modifier and Type Method
      static <T,​U>
      T
      objArr​(JsonArray ja, Object defaultValue, int FLAGS, Class<T> retArrClass)
       
      Read a JsonArray into a Multi-Dimensional String-Array
      Modifier and Type Method
      static <T> T strArr​(JsonArray ja, String defaultValue, int FLAGS, Class<T> retArrClass)
       
      Read a JsonArray into a Multi-Dimensional Primitive-Array
      Modifier and Type Method
      static <T> T booleanArr​(JsonArray ja, boolean defaultValue, int FLAGS, Predicate<String> optionalUserParser, Class<T> retArrClass)
      static <T> T byteArr​(JsonArray ja, byte defaultValue, int FLAGS, ToByteFunction<String> optionalUserParser, Class<T> retArrClass)
      static <T> T doubleArr​(JsonArray ja, double defaultValue, int FLAGS, ToDoubleFunction<String> optionalUserParser, Class<T> retArrClass)
      static <T> T floatArr​(JsonArray ja, float defaultValue, int FLAGS, ToFloatFunction<String> optionalUserParser, Class<T> retArrClass)
      static <T> T intArr​(JsonArray ja, int defaultValue, int FLAGS, ToIntFunction<String> optionalUserParser, Class<T> retArrClass)
      static <T> T longArr​(JsonArray ja, long defaultValue, int FLAGS, ToLongFunction<String> optionalUserParser, Class<T> retArrClass)
      static <T> T shortArr​(JsonArray ja, short defaultValue, int FLAGS, ToShortFunction<String> optionalUserParser, Class<T> retArrClass)
       
      Read a JsonArray into a Multi-Dimensional Boxed-Type Array
      Modifier and Type Method
      static <T> T arrBOOLEAN​(JsonArray ja, boolean defaultValue, int FLAGS, Function<String,​Boolean> optionalUserParser, Class<T> retArrClass)
      static <T> T arrBYTE​(JsonArray ja, byte defaultValue, int FLAGS, Function<String,​Byte> optionalUserParser, Class<T> retArrClass)
      static <T> T arrDOUBLE​(JsonArray ja, double defaultValue, int FLAGS, Function<String,​Double> optionalUserParser, Class<T> retArrClass)
      static <T> T arrFLOAT​(JsonArray ja, float defaultValue, int FLAGS, Function<String,​Float> optionalUserParser, Class<T> retArrClass)
      static <T> T arrINTEGER​(JsonArray ja, int defaultValue, int FLAGS, Function<String,​Integer> optionalUserParser, Class<T> retArrClass)
      static <T> T arrLONG​(JsonArray ja, long defaultValue, int FLAGS, Function<String,​Long> optionalUserParser, Class<T> retArrClass)
      static <T> T arrNumber​(JsonArray ja, Number defaultValue, int FLAGS, Function<String,​Number> optionalUserParser, Class<T> retArrClass)
      static <T> T arrSHORT​(JsonArray ja, short defaultValue, int FLAGS, Function<String,​Short> optionalUserParser, Class<T> retArrClass)
       
      Protected, Internal Methods
      Modifier and Type Method
      protected static <T> T jsonArrToJavaArr​(JsonArray ja, Torello.Java.JSON.ReadArrJSON.RECORD<?,​?> rec, Class<T> retArrClass)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • intArr

        🡇     🗕  🗗  🗖
        public static <T> T intArr​
                    (JsonArray ja,
                     int defaultValue,
                     int FLAGS,
                     java.util.function.ToIntFunction<java.lang.String> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: int Configuration-RECORD
        Removes: Any FLAGS that would produce a null array-entry

        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal int-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         int[][] arr = ReadArrJSON.DimN.intArr(jsonArray, -1, 0, null, int[][].class);
        
      • longArr

        🡅  🡇     🗕  🗗  🗖
        public static <T> T longArr​
                    (JsonArray ja,
                     long defaultValue,
                     int FLAGS,
                     java.util.function.ToLongFunction<java.lang.String> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: long Configuration-RECORD
        Removes: Any FLAGS that would produce a null array-entry

        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal long-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         long[][] arr = ReadArrJSON.DimN.longArr(jsonArray, -1, 0, null, long[][].class);
        
      • doubleArr

        🡅  🡇     🗕  🗗  🗖
        public static <T> T doubleArr​
                    (JsonArray ja,
                     double defaultValue,
                     int FLAGS,
                     java.util.function.ToDoubleFunction<java.lang.String> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: double Configuration-RECORD
        Removes: Any FLAGS that would produce a null array-entry

        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal double-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         double[][] arr = ReadArrJSON.DimN.doubleArr(jsonArray, -1, 0, null, double[][].class);
        
      • shortArr

        🡅  🡇     🗕  🗗  🗖
        public static <T> T shortArr​
                    (JsonArray ja,
                     short defaultValue,
                     int FLAGS,
                     ToShortFunction<java.lang.String> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: short Configuration-RECORD
        Removes: Any FLAGS that would produce a null array-entry

        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal short-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         short[][] arr = ReadArrJSON.DimN.shortArr(jsonArray, -1, 0, null, short[][].class);
        
      • byteArr

        🡅  🡇     🗕  🗗  🗖
        public static <T> T byteArr​
                    (JsonArray ja,
                     byte defaultValue,
                     int FLAGS,
                     ToByteFunction<java.lang.String> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: byte Configuration-RECORD
        Removes: Any FLAGS that would produce a null array-entry

        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal byte-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         byte[][] arr = ReadArrJSON.DimN.byteArr(jsonArray, -1, 0, null, byte[][].class);
        
      • floatArr

        🡅  🡇     🗕  🗗  🗖
        public static <T> T floatArr​
                    (JsonArray ja,
                     float defaultValue,
                     int FLAGS,
                     ToFloatFunction<java.lang.String> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: float Configuration-RECORD
        Removes: Any FLAGS that would produce a null array-entry

        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal float-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         float[][] arr = ReadArrJSON.DimN.floatArr(jsonArray, -1, 0, null, float[][].class);
        
      • booleanArr

        🡅  🡇     🗕  🗗  🗖
        public static <T> T booleanArr​
                    (JsonArray ja,
                     boolean defaultValue,
                     int FLAGS,
                     java.util.function.Predicate<java.lang.String> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: boolean Configuration-RECORD
        Removes: Any FLAGS that would produce a null array-entry

        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal boolean-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         boolean[][] arr = ReadArrJSON.DimN.booleanArr
              (jsonArray, -1, 0, null, boolean[][].class);
        
      • arrINTEGER

        🡅  🡇     🗕  🗗  🗖
        public static <T> T arrINTEGER​
                    (JsonArray ja,
                     int defaultValue,
                     int FLAGS,
                     java.util.function.Function<java.lang.String,​java.lang.Integer> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: Integer Configuration-RECORD
        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal Integer-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         Integer[][] arr = ReadArrJSON.DimN.arrINTEGER(jsonArray, -1, 0, null, Integer[][].class);
        
      • arrLONG

        🡅  🡇     🗕  🗗  🗖
        public static <T> T arrLONG​
                    (JsonArray ja,
                     long defaultValue,
                     int FLAGS,
                     java.util.function.Function<java.lang.String,​java.lang.Long> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: Long Configuration-RECORD
        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal Long-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         Long[][] arr = ReadArrJSON.DimN.arrLONG(jsonArray, -1, 0, null, Long[][].class);
        
      • arrDOUBLE

        🡅  🡇     🗕  🗗  🗖
        public static <T> T arrDOUBLE​
                    (JsonArray ja,
                     double defaultValue,
                     int FLAGS,
                     java.util.function.Function<java.lang.String,​java.lang.Double> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: Double Configuration-RECORD
        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal Double-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         Double[][] arr = ReadArrJSON.DimN.arrDOUBLE(jsonArray, -1, 0, null, Double[][].class);
        
      • arrSHORT

        🡅  🡇     🗕  🗗  🗖
        public static <T> T arrSHORT​
                    (JsonArray ja,
                     short defaultValue,
                     int FLAGS,
                     java.util.function.Function<java.lang.String,​java.lang.Short> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: Short Configuration-RECORD
        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal Short-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         Short[][] arr = ReadArrJSON.DimN.arrSHORT(jsonArray, -1, 0, null, Short[][].class);
        
      • arrBYTE

        🡅  🡇     🗕  🗗  🗖
        public static <T> T arrBYTE​
                    (JsonArray ja,
                     byte defaultValue,
                     int FLAGS,
                     java.util.function.Function<java.lang.String,​java.lang.Byte> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: Byte Configuration-RECORD
        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal Byte-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         Byte[][] arr = ReadArrJSON.DimN.arrBYTE(jsonArray, -1, 0, null, Byte[][].class);
        
      • arrFLOAT

        🡅  🡇     🗕  🗗  🗖
        public static <T> T arrFLOAT​
                    (JsonArray ja,
                     float defaultValue,
                     int FLAGS,
                     java.util.function.Function<java.lang.String,​java.lang.Float> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: Float Configuration-RECORD
        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal Float-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         Float[][] arr = ReadArrJSON.DimN.arrFLOAT(jsonArray, -1, 0, null, Float[][].class);
        
      • arrBOOLEAN

        🡅  🡇     🗕  🗗  🗖
        public static <T> T arrBOOLEAN​
                    (JsonArray ja,
                     boolean defaultValue,
                     int FLAGS,
                     java.util.function.Function<java.lang.String,​java.lang.Boolean> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: Boolean Configuration-RECORD
        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal Boolean-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         Boolean[][] arr = ReadArrJSON.DimN.arrBOOLEAN
              (jsonArray, false, 0, null, Boolean[][].class);
        
      • arrNumber

        🡅  🡇     🗕  🗗  🗖
        public static <T> T arrNumber​
                    (JsonArray ja,
                     java.lang.Number defaultValue,
                     int FLAGS,
                     java.util.function.Function<java.lang.String,​java.lang.Number> optionalUserParser,
                     java.lang.Class<T> retArrClass)
        
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: Number Configuration-RECORD
        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal Number-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         Number[][] arr = ReadArrJSON.DimN.arrNumber(jsonArray, -1, 0, null, Number[][].class);
        
      • strArr

        🡅  🡇     🗕  🗗  🗖
        public static <T> T strArr​(JsonArray ja,
                                   java.lang.String defaultValue,
                                   int FLAGS,
                                   java.lang.Class<T> retArrClass)
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: String Configuration-RECORD
        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal String-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         String[][] arr = ReadArrJSON.DimN.strArr(jsonArray, null, 0, String[][].class);
        
      • objArr

        🡅  🡇     🗕  🗗  🗖
        public static <T,​U> T objArr​(JsonArray ja,
                                           java.lang.Object defaultValue,
                                           int FLAGS,
                                           java.lang.Class<T> retArrClass)
        Convenience Method
        Invokes: jsonArrToJavaArr(JsonArray, ReadArrJSON.RECORD, Class)
        Passes: Object Configuration-RECORD
        See link above for more JFlag explanations.
        NOTE: retArrClass must be a multi-dimensinal Object-array.
        (See last "return-type" parameter in example below)

        Java Line of Code:
         MyClass[][] arr = ReadArrJSON.DimN.strArr(jsonArray, null, 0, MyClass[][].class);