Package Torello.Java.JSON
Class RJArrIntoConsumer
- java.lang.Object
-
- Torello.Java.JSON.RJArrIntoConsumer
-
public class RJArrIntoConsumer extends java.lang.Object
Each of the methods in this class, all declared'static'
, accept a standardJsonArray
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 singleJsonArray
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
andJsonObject
JSON Binding Helper-Class:
JSON-Binding is the art of converting data that has been stored, saved or transmitted usingJava-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
Hi-Lited Source-Code:This File's Source Code:
- View Here: Torello/Java/JSON/RJArrIntoConsumer.java
- Open New Browser-Tab: Torello/Java/JSON/RJArrIntoConsumer.java
File Size: 6,972 Bytes Line Count: 178 '\n' Characters Found
Json-Array Reader-Helper:
- View Here: BASIC_TYPES.java
- Open New Browser-Tab: BASIC_TYPES.java
File Size: 16,119 Bytes Line Count: 393 '\n' Characters Found
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)
- Utilizes the Java-Standard
-
-
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)
-
-
-
Method Detail
-
objArr
public static <T> void objArr(JsonArray ja, T defaultValue, int FLAGS, java.lang.Class<T> consumerClass, java.util.function.Consumer<T> c)
Converts aJsonArray
into aStream<T>
. It is important to remember that the packageTorello.Java.JSON
does not attempt to generate Java-Type's or their Constructors. The 'Type' of theStream<T>
that is returned by this method (the value of'T'
) must be an Object-Class that contains a Constructor that accepts aJsonObject
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 beAutomobile.class
.- Parameters:
ja
- AnyJsonArray
, 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. SeeJFlag
for details.consumerClass
- Thejava.lang.Class
of theConsumer
-Type currently being used.
-
strArray
public static void strArray (JsonArray ja, java.lang.String defaultValue, int FLAGS, java.util.function.Consumer<java.lang.String> c)
Iterates aJsonArray
and passes the retrieved values to a User-Provided Consumer- Parameters:
ja
- AnyJsonArray
, but preferrably one which contains instances ofJsonString
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. SeeJFlag
for details.
-
objArr2
public static <T> void objArr2(JsonArray ja, T defaultValue, int FLAGS, java.lang.Class<T> consumerClass, IntIntTConsumer<T> c)
Converts aJsonArray
into aStream<T>
. It is important to remember that the packageTorello.Java.JSON
does not attempt to generate Java-Type's or their Constructors. The 'Type' of theStream<T>
that is returned by this method (the value of'T'
) must be an Object-Class that contains a Constructor that accepts aJsonObject
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 beAutomobile.class
.- Parameters:
ja
- AnyJsonArray
, 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. SeeJFlag
for details.consumerClass
- Thejava.lang.Class
of theIntIntTConsumer
-Type currently being used.
-
strArray2
public static void strArray2(JsonArray ja, java.lang.String defaultValue, int FLAGS, IntIntTConsumer<java.lang.String> c)
Iterates aJsonArray
and passes the retrieved values to a User-Provided Consumer- Parameters:
ja
- AnyJsonArray
, but preferrably one which contains instances ofJsonString
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. SeeJFlag
for details.
-
-