Class RJArrIntoConsumer


  • public class RJArrIntoConsumer
    extends java.lang.Object
    Each of the methods in this class, all declared 'static', accept a standard JsonArray as input, and make a (User-Specified) "Best Efforts" attempt to convert each of the elements of the array into Java-String's or other, arbitrary, Java-Object's. Each Json-Array Element that is successfully converted into one of these two types is then, subsequently, passed to a (User-Provided) Java-Consumer.

    Each method in this class expects the user to provide a single JsonArray as input, along with a Java 'Consumer' reference / instance.
    Utilities for parsing Json Array's and sending the parsed values into a Java Consumer Functional-Interface.

    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


    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
    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
    • 4 Method(s), 4 declared static
    • 0 Field(s)


    • Method Summary

       
      Read the Contents of a Json-Array into a Java-Consumer
      Modifier and Type Method
      static <T> void objArr​(JsonArray ja, T defaultValue, int FLAGS, Class<T> consumerClass, Consumer<T> c)
      static void strArray​(JsonArray ja, String defaultValue, int FLAGS, Consumer<String> c)
       
      Read the Contents of a Json-Array into a Consumer w/ Array-Indices
      Modifier and Type Method
      static <T> void objArr2​(JsonArray ja, T defaultValue, int FLAGS, Class<T> consumerClass, IntIntTConsumer<T> c)
      static void strArray2​(JsonArray ja, String defaultValue, int FLAGS, IntIntTConsumer<String> c)
      • Methods inherited from class java.lang.Object

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

      • objArr

        🡇         External-Java:    🗕  🗗  🗖
        public static <T> void objArr​(JsonArray ja,
                                      T defaultValue,
                                      int FLAGS,
                                      java.lang.Class<T> consumerClass,
                                      java.util.function.Consumer<T> c)
        Converts a JsonArray into a Stream<T>. It is important to remember that the package Torello.Java.JSON does not attempt to generate Java-Type's or their Constructors. The 'Type' of the Stream<T> that is returned by this method (the value of 'T') must be an Object-Class that contains a Constructor that accepts a JsonObject as input.

        This package does not perform the type of Auto-Type-Generation that is done by Lombok or Jackson.
        Type Parameters:
        T - This is the 'type' of the array being built. If there were a class, for example, named 'Automobile', the value passed to parameter 'returnClass' would simply be Automobile.class.
        Parameters:
        ja - Any JsonArray, but preferrably one which contains instances of the class that has been specified by Type-Parameter 'T'
        defaultValue - When used in conjunction with 'FLAGS', this default-value may be inserted into the output-array when error-cases occur while interpreting the array contents.
        FLAGS - Optional flags. See JFlag for details.
        consumerClass - The java.lang.Class of the Consumer-Type currently being used.
      • strArray

        🡅  🡇         External-Java:    🗕  🗗  🗖
        public static void strArray​
                    (JsonArray ja,
                     java.lang.String defaultValue,
                     int FLAGS,
                     java.util.function.Consumer<java.lang.String> c)
        
        Iterates a JsonArray and passes the retrieved values to a User-Provided Consumer
        Parameters:
        ja - Any JsonArray, but preferrably one which contains instances of JsonString
        defaultValue - When used in conjunction with 'FLAGS', this default-value may be inserted into the output-array when error cases occur at particular array-index locations.
        FLAGS - Optional flags. See JFlag for details.
      • objArr2

        🡅  🡇         External-Java:    🗕  🗗  🗖
        public static <T> void objArr2​(JsonArray ja,
                                       T defaultValue,
                                       int FLAGS,
                                       java.lang.Class<T> consumerClass,
                                       IntIntTConsumer<T> c)
        Converts a JsonArray into a Stream<T>. It is important to remember that the package Torello.Java.JSON does not attempt to generate Java-Type's or their Constructors. The 'Type' of the Stream<T> that is returned by this method (the value of 'T') must be an Object-Class that contains a Constructor that accepts a JsonObject as input.

        This package does not perform the type of Auto-Type-Generation that is done by Lombok or Jackson.
        Type Parameters:
        T - This is the 'type' of the array being built. If there were a class, for example, named 'Automobile', the value passed to parameter 'returnClass' would simply be Automobile.class.
        Parameters:
        ja - Any JsonArray, but preferrably one which contains instances of the class that has been specified by Type-Parameter 'T'
        defaultValue - When used in conjunction with 'FLAGS', this default-value may be inserted into the output-array when error-cases occur while interpreting the array contents.
        FLAGS - Optional flags. See JFlag for details.
        consumerClass - The java.lang.Class of the IntIntTConsumer-Type currently being used.
      • strArray2

        🡅         External-Java:    🗕  🗗  🗖
        public static void strArray2​(JsonArray ja,
                                     java.lang.String defaultValue,
                                     int FLAGS,
                                     IntIntTConsumer<java.lang.String> c)
        Iterates a JsonArray and passes the retrieved values to a User-Provided Consumer
        Parameters:
        ja - Any JsonArray, but preferrably one which contains instances of JsonString
        defaultValue - When used in conjunction with 'FLAGS', this default-value may be inserted into the output-array when error cases occur at particular array-index locations.
        FLAGS - Optional flags. See JFlag for details.