Package Torello.Java.JSON
Class RJArrDimN
- java.lang.Object
-
- Torello.Java.JSON.RJArrDimN
-
public class RJArrDimN extends java.lang.Object
RJArrIntoDimN 🠞RJArr
- ReadJsonArray
This class is used for reading data directly from an already parsedJsonArray
instance.
DimN
- Data is sent to a Multi-Dimensional, User-Specified, Java-Array.
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
andJsonObject
This class offers a straightforward way to convert Multi-DimensionalJsonArray
instances into Multi-Dimensional Java-Arrays. It is only required that the actual final class of the desired output array be provided as input to the method that shall perform this processing.
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
The class allows a user to extract any Java array-type (including Primitive-Arrays) having any number of dimensions for the array, from aJsonArray
.
JSON-Array Types:JsonArray's
are allowed quite a bit of leeway in how their data is arranged. First, aJsonArray
isn't required to contain a single type of data object. An array may have aJsonString
followed by threeJsonNumber's
, and end with anotherJsonArray
. Java does not allow such array types.
In Java, for instance, a two-dimensionalString
-Array may only have actualString
-references in the second-dimensional arrays! The first-dimension of the array must containString[]
array pointers, or nulls. AJsonArray
could contain severalString's
follwed by another, nested,JsonArray
ofString'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 followingJsonArray
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-DimensionalString[]
-Array. In Java, the first dimension of the array may only contain sub-arrays of typeString[]
. It is the Second-Dimension that may actually haveString
-References.
Parsing the aboveJsonArray
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 ofJsonArray
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. Thejava.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-dimensionalString
-Array, one would use the following line of code. Note that the appropriate class is simply obtained by appending'.class'
to the end of theString
-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);
Hi-Lited Source-Code:This File's Source Code:
- View Here: Torello/Java/JSON/RJArrDimN.java
- Open New Browser-Tab: Torello/Java/JSON/RJArrDimN.java
File Size: 28,555 Bytes Line Count: 692 '\n' Characters Found
Build a Settings-Record, Helper Class:
- View Here: BASIC_TYPES.java
- Open New Browser-Tab: BASIC_TYPES.java
File Size: 27,692 Bytes Line Count: 586 '\n' Characters Found
Build a Settings-Record, Helper Class:
- View Here: GENERATE_1DARRAY.java
- Open New Browser-Tab: GENERATE_1DARRAY.java
File Size: 7,907 Bytes Line Count: 241 '\n' Characters Found
Build a Settings-Record, Helper Class:
- View Here: SETTINGS_REC_BUILDER.java
- Open New Browser-Tab: SETTINGS_REC_BUILDER.java
File Size: 6,080 Bytes Line Count: 152 '\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
- 18 Method(s), 18 declared static
- 3 Field(s), 3 declared static, 3 declared final
-
-
Method Summary
Read a JsonArray
into a Multi-DimensionalObject
-ArrayModifier and Type Method static <RET_ARR_CLASS>
RET_ARR_CLASSobjArr(JsonArray ja, Object defaultValue, int FLAGS, Class<RET_ARR_CLASS> retArrClass)
Read a JsonArray
into a Multi-DimensionalString
-ArrayModifier and Type Method static <T> T
strArr(JsonArray ja, String defaultValue, int FLAGS, Class<T> retArrClass)
Read a JsonArray
into a Multi-Dimensional Primitive-ArrayModifier 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-Primitive ArrayModifier 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 Helper Methods Modifier and Type Method protected static <T> Class<T>
CHECK_ARRAY_CLASS(Class<T> retArrClass, Class<?> expectedRootClass)
-
-
-
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)
Multi-Dimensional Array of Primitive-IntegersInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: An int
Configurations / SettingsRecRemoves: Any JFlag
masks which might insert null-entries in the return-streamSee: Class JFlag
for information about parameter'FLAGS'
See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKS
for a list of all disallowed & filtered flags.Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalint
-Array Type.(Notice the "return-type" parameter which is passed in the 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)
Multi-Dimensional Array of Primitive Long-IntegersInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A long
Configurations / SettingsRecRemoves: Any JFlag
masks which might insert null-entries in the return-streamSee: Class JFlag
for information about parameter'FLAGS'
See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKS
for a list of all disallowed & filtered flags.Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinallong
-Array Type.(Notice the "return-type" parameter which is passed in the 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)
Multi-Dimensional Array of Primitive-DoublesInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A double
Configurations / SettingsRecRemoves: Any JFlag
masks which might insert null-entries in the return-streamSee: Class JFlag
for information about parameter'FLAGS'
See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKS
for a list of all disallowed & filtered flags.Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinaldouble
-Array Type.(Notice the "return-type" parameter which is passed in the example below)
Java Line of Code:
double[][] arr = ReadArrJSON.DimN.doubleArr(jsonArray, -1.0, 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)
Multi-Dimensional Array of Primitive Short-IntegersInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A short
Configurations / SettingsRecRemoves: Any JFlag
masks which might insert null-entries in the return-streamSee: Class JFlag
for information about parameter'FLAGS'
See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKS
for a list of all disallowed & filtered flags.Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalshort
-Array Type.(Notice the "return-type" parameter which is passed in the 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)
Multi-Dimensional Array of Primitive-BytesInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A byte
Configurations / SettingsRecRemoves: Any JFlag
masks which might insert null-entries in the return-streamSee: Class JFlag
for information about parameter'FLAGS'
See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKS
for a list of all disallowed & filtered flags.Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalbyte
-Array Type.(Notice the "return-type" parameter which is passed in the 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)
Multi-Dimensional Array of Primitive-FloatsInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A float
Configurations / SettingsRecRemoves: Any JFlag
masks which might insert null-entries in the return-streamSee: Class JFlag
for information about parameter'FLAGS'
See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKS
for a list of all disallowed & filtered flags.Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalfloat
-Array Type.(Notice the "return-type" parameter which is passed in the example below)
Java Line of Code:
float[][] arr = ReadArrJSON.DimN.floatArr(jsonArray, -1.0f, 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)
Multi-Dimensional Array of Primitive-BooleansInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A boolean
Configurations / SettingsRecRemoves: Any JFlag
masks which might insert null-entries in the return-streamSee: Class JFlag
for information about parameter'FLAGS'
See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKS
for a list of all disallowed & filtered flags.Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalboolean
-Array Type.(Notice the "return-type" parameter which is passed in the example below)
Java Line of Code:
boolean[][] arr = ReadArrJSON.DimN.booleanArr(jsonArray, false, 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)
Multi-Dimensional Array of Boxed-IntegersInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: An Integer
Configurations / SettingsRecSee: Class JFlag
for information about parameter'FLAGS'
Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalInteger
-Array Type.(Notice the "return-type" parameter which is passed in the 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)
Multi-Dimensional Array of Boxed Long-IntegersInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A Long
Configurations / SettingsRecSee: Class JFlag
for information about parameter'FLAGS'
Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalLong
-Array Type.(Notice the "return-type" parameter which is passed in the 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)
Multi-Dimensional Array of Boxed-DoublesInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A Double
Configurations / SettingsRecSee: Class JFlag
for information about parameter'FLAGS'
Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalDouble
-Array Type.(Notice the "return-type" parameter which is passed in the example below)
Java Line of Code:
Double[][] arr = ReadArrJSON.DimN.arrDOUBLE(jsonArray, -1.0, 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)
Multi-Dimensional Array of Boxed Short-IntegersInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A Short
Configurations / SettingsRecSee: Class JFlag
for information about parameter'FLAGS'
Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalShort
-Array Type.(Notice the "return-type" parameter which is passed in the 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)
Multi-Dimensional Array of Boxed-BytesInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A Byte
Configurations / SettingsRecSee: Class JFlag
for information about parameter'FLAGS'
Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalByte
-Array Type.(Notice the "return-type" parameter which is passed in the 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)
Multi-Dimensional Array of Boxed-FloatsInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A Float
Configurations / SettingsRecSee: Class JFlag
for information about parameter'FLAGS'
Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalFloat
-Array Type.(Notice the "return-type" parameter which is passed in the example below)
Java Line of Code:
Float[][] arr = ReadArrJSON.DimN.arrFLOAT(jsonArray, -1.0f, 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)
Multi-Dimensional Array of Boxed-BooleansInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A Boolean
Configurations / SettingsRecSee: Class JFlag
for information about parameter'FLAGS'
Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalBoolean
-Array Type.(Notice the "return-type" parameter which is passed in the 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)
Multi-Dimensional Array of Best-Fit Boxed-NumbersInvokes: Method ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: A Number
Configurations / SettingsRecSee: Class JFlag
for information about parameter'FLAGS'
Note: The 'Type' of Parameter retArrClass
must be a multi-dimensinalNumber
-Array Type.(Notice the "return-type" parameter which is passed in the example below)
Java Line of Code:
Number[][] arr = ReadArrJSON.DimN.arrNumber(jsonArray, 0, 0, null, Number[][].class);
-
strArr
public static <T> T strArr(JsonArray ja, java.lang.String defaultValue, int FLAGS, java.lang.Class<T> retArrClass)
Multi-Dimensional Array of StringsInvokes: ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: String
Configurations / SettingsRecSee: Class JFlag
for more information about parameter'FLAGS'
.Note: retArrClass
must be a multi-dimensinalString
-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 <RET_ARR_CLASS> RET_ARR_CLASS objArr (JsonArray ja, java.lang.Object defaultValue, int FLAGS, java.lang.Class<RET_ARR_CLASS> retArrClass)
Multi-Dimensional Array of Object <T>Invokes: ProcessMultiDimJsonArray.jsonArrayToJava(JsonArray, SettingsRec, Class)
Passes: Object
Configurations / SettingsRecSee: class JFlag
for more information about parameter'FLAGS'
.Note: retArrClass
must be a multi-dimensinalObject
-array.(See last "return-type" parameter in example below)
Java Line of Code:
MyClass[][] arr = ReadArrJSON.DimN.strArr(jsonArray, null, 0, MyClass[][].class);
-
CHECK_ARRAY_CLASS
protected static <T> java.lang.Class<T> CHECK_ARRAY_CLASS (java.lang.Class<T> retArrClass, java.lang.Class<?> expectedRootClass)
Check user input, and throws exceptions if the array-class has not been properly chosen.- Parameters:
retArrClass
- This must be a primitive-array class, possibly of multiple dimensionsexpectedRootClass
- The expected "root class". Forint[][].class
, the root class would beint.class
.- Returns:
- Parameter
retArrClass
is the return value of this checker method - Throws:
IllegalArgumentExcetion
- If parameter retArrClass: If calling retArrClass.isArray() returns FALSE If the root-array type is not the appropriate type for the method that was called
-
-