Package Torello.Java.Additional
Class ReadJSON.XL
- java.lang.Object
-
- Torello.Java.Additional.ReadJSON.XL
-
- Enclosing class:
- ReadJSON
public static class ReadJSON.XL extends java.lang.Object
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:- Provides for All-Manner of Exception-Handling & Error-Decision Configurations using the
(Simple)
JFlag
Class. - Provides Fine-Grained JSON Exception-Classes, all of which have Pre-written & Consistent Error-Messages,
- Handles the Transfer & Conversion of All Json-Type's into Java-Type's in just One Line of Code
- Is a Core Handler-Class for the (Experimental) Google-Chrome
Headless Browser
Package - Utilizes the Java-Standard
javax.json.*
Package-Library
More utilities for parsing and converting JSON Data into Java Data Types.
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 provides an additional set of methods for handling properties that should contain numbers, but could possibly contain those numbers represented asString's
. This class also handles creating POJO's.
This class facilitates handling any type of Json Data when converting Json Types to Java Types, and essentially builds on the methods available in classReadJSON
.
POJO De-Serialization:
The methods that appear to de-serialize a JSON Object into a standard Java-Object require a constructor that accepts aJsonObject
. Automatic type-creation (as exists in libraries such as 'Lombok') is not an feature offered by this class. There is not a lot of "magic", however these methods can reduce a lot of the work needed to convert Json into Java through field initializations that have been reduced to nothing more than a single line of code.
Te primary value of theFLAGS
configuration-parameters and other assorted boolean-parameters are just to ensure that if / when erroneous JSON is received from a REST Web-Service, that it is instantly and automatically handled appropriately. Dealing with such erroneous input can be accomplished through default-values, exception-throws or null-values.
The exception messages provided by this package are extremely readable, and contain al the information needed when debugging REST-API interfaces.- See Also:
Json
,JsonObject
,JsonArray
Hi-Lited Source-Code:- View Here: Torello/Java/Additional/ReadJSON.java
- Open New Browser-Tab: Torello/Java/Additional/ReadJSON.java
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
- 19 Method(s), 19 declared static
- 0 Field(s)
-
-
Method Summary
Retrieve a JsonObject
, and transform it to a Java ObjectReturns Modifier and Type Method Object static <T> T
getObject(JsonArray ja, int index, Class<T> c, boolean throwOnNull)
Object static <T> T
getObject(JsonObject jo, Class<T> c)
Object static <T> T
getObject(JsonObject jo, String propertyName, Class<T> c, boolean isOptional, boolean throwOnNull)
Retrieve either a JsonNumber
orJsonString
from aJsonArray
, and transform to numberReturns Modifier and Type Method Boxed-Primitive static Byte
getBYTE(JsonArray ja, int i, int FLAGS, byte defaultValue, Function<String,Byte> optionalParser)
Boxed-Primitive static Double
getDOUBLE(JsonArray ja, int i, int FLAGS, double defaultValue, Function<String,Double> optionalParser)
Boxed-Primitive static Float
getFLOAT(JsonArray ja, int i, int FLAGS, float defaultValue, Function<String,Float> optionalParser)
Boxed-Primitive static Integer
getINTEGER(JsonArray ja, int i, int FLAGS, int defaultValue, Function<String,Integer> optionalParser)
Boxed-Primitive static Long
getLONG(JsonArray ja, int i, int FLAGS, long defaultValue, Function<String,Long> optionalParser)
Boxed-Primitive static Number
getNUMBER(JsonArray ja, int i, int FLAGS, Number defaultValue, Function<String,Number> optionalParser)
Boxed-Primitive static Short
getSHORT(JsonArray ja, int i, int FLAGS, short defaultValue, Function<String,Short> optionalParser)
Retrieve either a JsonNumber
orJsonString
from aJsonObject
, and transform to numberReturns Modifier and Type Method Boxed-Primitive static Byte
getBYTE(JsonObject jo, String propertyName, int FLAGS, byte defaultValue, Function<String,Byte> optionalParser)
Boxed-Primitive static Double
getDOUBLE(JsonObject jo, String propertyName, int FLAGS, double defaultValue, Function<String,Double> optionalParser)
Boxed-Primitive static Float
getFLOAT(JsonObject jo, String propertyName, int FLAGS, float defaultValue, Function<String,Float> optionalParser)
Boxed-Primitive static Integer
getINTEGER(JsonObject jo, String propertyName, int FLAGS, int defaultValue, Function<String,Integer> optionalParser)
Boxed-Primitive static Long
getLONG(JsonObject jo, String propertyName, int FLAGS, long defaultValue, Function<String,Long> optionalParser)
Boxed-Primitive static Number
getNUMBER(JsonObject jo, String propertyName, int FLAGS, Number defaultValue, Function<String,Number> optionalParser)
Boxed-Primitive static Short
getSHORT(JsonObject jo, String propertyName, int FLAGS, short defaultValue, Function<String,Short> optionalParser)
Retrieve JsonValue.TRUE
,FALSE
, or aJsonString
, and transform to booleanReturns Modifier and Type Method Boxed-Primitive static Boolean
getBOOLEAN(JsonArray ja, int i, int FLAGS, boolean defaultValue, Function<String,Boolean> optionalParser)
Boxed-Primitive static Boolean
getBOOLEAN(JsonObject jo, String propertyName, int FLAGS, boolean defaultValue, Function<String,Boolean> optionalParser)
-
-
-
Method Detail
-
getINTEGER
public static java.lang.Integer getINTEGER (JsonArray ja, int i, int FLAGS, int defaultValue, java.util.function.Function<java.lang.String,java.lang.Integer> optionalParser)
Used to convert aJsonArray
element which can handle either aString
, or aNumber
, and transform that element into a JavaInteger
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether a string or a number is found at the array index location.- Parameters:
ja
- AnyJsonArray
i
- Any index into theJsonArray
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaInteger
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toInteger
parser-function is required to generate the result for this method, thenInteger.parseInt(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonArray
index contained a number, and that number was successfully transformed to aInteger
, then it is returned.
If the array-index was aString
, and thatString
was transformed into aInteger
using either'parser'
- or the default parser, then thatInteger
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of input array'ja'
and none of these Exception-Flags are set:RETURN_NULL_ON_IOB
(Abbrev:RN_IOB
)RETURN_DEFVAL_ON_IOB
(Abbrev:RD_IOB
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseArrException
- If theJsonArray
element located at'index'
contains aJsonString
, this method will attempt to parse thatString
into a JavaInteger
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Integer.parseInt(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullArrException
- If theJsonArray
element located at'index'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeArrException
- If theJsonArray
element located at'index'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getINTEGER(JsonArray, int, int, int)
,ReadJSON.parseINTEGER(JsonArray, int, int, int, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) ? ReadJSON.getINTEGER(ja, i, FLAGS, defaultValue) : ReadJSON.parseINTEGER(ja, i, FLAGS, defaultValue, optionalParser);
-
getLONG
public static java.lang.Long getLONG (JsonArray ja, int i, int FLAGS, long defaultValue, java.util.function.Function<java.lang.String,java.lang.Long> optionalParser)
Used to convert aJsonArray
element which can handle either aString
, or aNumber
, and transform that element into a JavaLong
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether a string or a number is found at the array index location.- Parameters:
ja
- AnyJsonArray
i
- Any index into theJsonArray
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaLong
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toLong
parser-function is required to generate the result for this method, thenLong.parseLong(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonArray
index contained a number, and that number was successfully transformed to aLong
, then it is returned.
If the array-index was aString
, and thatString
was transformed into aLong
using either'parser'
- or the default parser, then thatLong
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of input array'ja'
and none of these Exception-Flags are set:RETURN_NULL_ON_IOB
(Abbrev:RN_IOB
)RETURN_DEFVAL_ON_IOB
(Abbrev:RD_IOB
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseArrException
- If theJsonArray
element located at'index'
contains aJsonString
, this method will attempt to parse thatString
into a JavaLong
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Long.parseLong(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullArrException
- If theJsonArray
element located at'index'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeArrException
- If theJsonArray
element located at'index'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getLONG(JsonArray, int, int, long)
,ReadJSON.parseLONG(JsonArray, int, int, long, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) ? ReadJSON.getLONG(ja, i, FLAGS, defaultValue) : ReadJSON.parseLONG(ja, i, FLAGS, defaultValue, optionalParser);
-
getSHORT
public static java.lang.Short getSHORT (JsonArray ja, int i, int FLAGS, short defaultValue, java.util.function.Function<java.lang.String,java.lang.Short> optionalParser)
Used to convert aJsonArray
element which can handle either aString
, or aNumber
, and transform that element into a JavaShort
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether a string or a number is found at the array index location.- Parameters:
ja
- AnyJsonArray
i
- Any index into theJsonArray
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaShort
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toShort
parser-function is required to generate the result for this method, thenShort.parseShort(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonArray
index contained a number, and that number was successfully transformed to aShort
, then it is returned.
If the array-index was aString
, and thatString
was transformed into aShort
using either'parser'
- or the default parser, then thatShort
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of input array'ja'
and none of these Exception-Flags are set:RETURN_NULL_ON_IOB
(Abbrev:RN_IOB
)RETURN_DEFVAL_ON_IOB
(Abbrev:RD_IOB
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseArrException
- If theJsonArray
element located at'index'
contains aJsonString
, this method will attempt to parse thatString
into a JavaShort
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Short.parseShort(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullArrException
- If theJsonArray
element located at'index'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeArrException
- If theJsonArray
element located at'index'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getSHORT(JsonArray, int, int, short)
,ReadJSON.parseSHORT(JsonArray, int, int, short, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) ? ReadJSON.getSHORT(ja, i, FLAGS, defaultValue) : ReadJSON.parseSHORT(ja, i, FLAGS, defaultValue, optionalParser);
-
getBYTE
public static java.lang.Byte getBYTE (JsonArray ja, int i, int FLAGS, byte defaultValue, java.util.function.Function<java.lang.String,java.lang.Byte> optionalParser)
Used to convert aJsonArray
element which can handle either aString
, or aNumber
, and transform that element into a JavaByte
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether a string or a number is found at the array index location.- Parameters:
ja
- AnyJsonArray
i
- Any index into theJsonArray
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaByte
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toByte
parser-function is required to generate the result for this method, thenByte.parseByte(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonArray
index contained a number, and that number was successfully transformed to aByte
, then it is returned.
If the array-index was aString
, and thatString
was transformed into aByte
using either'parser'
- or the default parser, then thatByte
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of input array'ja'
and none of these Exception-Flags are set:RETURN_NULL_ON_IOB
(Abbrev:RN_IOB
)RETURN_DEFVAL_ON_IOB
(Abbrev:RD_IOB
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseArrException
- If theJsonArray
element located at'index'
contains aJsonString
, this method will attempt to parse thatString
into a JavaByte
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Byte.parseByte(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullArrException
- If theJsonArray
element located at'index'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeArrException
- If theJsonArray
element located at'index'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getBYTE(JsonArray, int, int, byte)
,ReadJSON.parseBYTE(JsonArray, int, int, byte, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) ? ReadJSON.getBYTE(ja, i, FLAGS, defaultValue) : ReadJSON.parseBYTE(ja, i, FLAGS, defaultValue, optionalParser);
-
getDOUBLE
public static java.lang.Double getDOUBLE (JsonArray ja, int i, int FLAGS, double defaultValue, java.util.function.Function<java.lang.String,java.lang.Double> optionalParser)
Used to convert aJsonArray
element which can handle either aString
, or aNumber
, and transform that element into a JavaDouble
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether a string or a number is found at the array index location.- Parameters:
ja
- AnyJsonArray
i
- Any index into theJsonArray
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaDouble
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toDouble
parser-function is required to generate the result for this method, thenDouble.parseDouble(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonArray
index contained a number, and that number was successfully transformed to aDouble
, then it is returned.
If the array-index was aString
, and thatString
was transformed into aDouble
using either'parser'
- or the default parser, then thatDouble
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of input array'ja'
and none of these Exception-Flags are set:RETURN_NULL_ON_IOB
(Abbrev:RN_IOB
)RETURN_DEFVAL_ON_IOB
(Abbrev:RD_IOB
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseArrException
- If theJsonArray
element located at'index'
contains aJsonString
, this method will attempt to parse thatString
into a JavaDouble
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Double.parseDouble(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullArrException
- If theJsonArray
element located at'index'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeArrException
- If theJsonArray
element located at'index'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getDOUBLE(JsonArray, int, int, double)
,ReadJSON.parseDOUBLE(JsonArray, int, int, double, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) ? ReadJSON.getDOUBLE(ja, i, FLAGS, defaultValue) : ReadJSON.parseDOUBLE(ja, i, FLAGS, defaultValue, optionalParser);
-
getFLOAT
public static java.lang.Float getFLOAT (JsonArray ja, int i, int FLAGS, float defaultValue, java.util.function.Function<java.lang.String,java.lang.Float> optionalParser)
Used to convert aJsonArray
element which can handle either aString
, or aNumber
, and transform that element into a JavaFloat
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether a string or a number is found at the array index location.- Parameters:
ja
- AnyJsonArray
i
- Any index into theJsonArray
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaFloat
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toFloat
parser-function is required to generate the result for this method, thenFloat.parseFloat(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonArray
index contained a number, and that number was successfully transformed to aFloat
, then it is returned.
If the array-index was aString
, and thatString
was transformed into aFloat
using either'parser'
- or the default parser, then thatFloat
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of input array'ja'
and none of these Exception-Flags are set:RETURN_NULL_ON_IOB
(Abbrev:RN_IOB
)RETURN_DEFVAL_ON_IOB
(Abbrev:RD_IOB
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseArrException
- If theJsonArray
element located at'index'
contains aJsonString
, this method will attempt to parse thatString
into a JavaFloat
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Float.parseFloat(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullArrException
- If theJsonArray
element located at'index'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeArrException
- If theJsonArray
element located at'index'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getFLOAT(JsonArray, int, int, float)
,ReadJSON.parseFLOAT(JsonArray, int, int, float, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) ? ReadJSON.getFLOAT(ja, i, FLAGS, defaultValue) : ReadJSON.parseFLOAT(ja, i, FLAGS, defaultValue, optionalParser);
-
getNUMBER
public static java.lang.Number getNUMBER (JsonArray ja, int i, int FLAGS, java.lang.Number defaultValue, java.util.function.Function<java.lang.String,java.lang.Number> optionalParser)
Used to convert aJsonArray
element which can handle either aString
, or aNumber
, and transform that element into a JavaNumber
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether a string or a number is found at the array index location.- Parameters:
ja
- AnyJsonArray
i
- Any index into theJsonArray
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaNumber
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toNumber
parser-function is required to generate the result for this method, thennew BigDecimal(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonArray
index contained a number, and that number was successfully transformed to aNumber
, then it is returned.
If the array-index was aString
, and thatString
was transformed into aNumber
using either'parser'
- or the default parser, then thatNumber
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of input array'ja'
and none of these Exception-Flags are set:RETURN_NULL_ON_IOB
(Abbrev:RN_IOB
)RETURN_DEFVAL_ON_IOB
(Abbrev:RD_IOB
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseArrException
- If theJsonArray
element located at'index'
contains aJsonString
, this method will attempt to parse thatString
into a JavaNumber
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (new BigDecimal(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullArrException
- If theJsonArray
element located at'index'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeArrException
- If theJsonArray
element located at'index'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getNUMBER(JsonArray, int, int, Number)
,ReadJSON.parseNUMBER(JsonArray, int, int, Number, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) ? ReadJSON.getNUMBER(ja, i, FLAGS, defaultValue) : ReadJSON.parseNUMBER(ja, i, FLAGS, defaultValue, optionalParser);
-
getBOOLEAN
public static java.lang.Boolean getBOOLEAN (JsonArray ja, int i, int FLAGS, boolean defaultValue, java.util.function.Function<java.lang.String,java.lang.Boolean> optionalParser)
Used to convert aJsonArray
element which can handle either aString
, or aNumber
, and transform that element into a JavaBoolean
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether a string or a number is found at the array index location.- Parameters:
ja
- AnyJsonArray
i
- Any index into theJsonArray
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaBoolean
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toBoolean
parser-function is required to generate the result for this method, thenBoolean.parseBoolean(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonArray
index contained a number, and that number was successfully transformed to aBoolean
, then it is returned.
If the array-index was aString
, and thatString
was transformed into aBoolean
using either'parser'
- or the default parser, then thatBoolean
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of input array'ja'
and none of these Exception-Flags are set:RETURN_NULL_ON_IOB
(Abbrev:RN_IOB
)RETURN_DEFVAL_ON_IOB
(Abbrev:RD_IOB
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseArrException
- If theJsonArray
element located at'index'
contains aJsonString
, this method will attempt to parse thatString
into a JavaBoolean
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Boolean.parseBoolean(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullArrException
- If theJsonArray
element located at'index'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeArrException
- If theJsonArray
element located at'index'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getBOOLEAN(JsonArray, int, int, boolean)
,ReadJSON.parseBOOLEAN(JsonArray, int, int, boolean, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ( (i >= ja.size()) || ((t=ja.get(i).getValueType()) == TRUE) || (t == FALSE) || (t != STRING) ) ? ReadJSON.getBOOLEAN(ja, i, FLAGS, defaultValue) : ReadJSON.parseBOOLEAN(ja, i, FLAGS, defaultValue, optionalParser);
-
getINTEGER
public static java.lang.Integer getINTEGER (JsonObject jo, java.lang.String propertyName, int FLAGS, int defaultValue, java.util.function.Function<java.lang.String,java.lang.Integer> optionalParser)
Used to convert aJsonObject
property which can handle either aString
, or aNumber
, and transform that element into a JavaInteger
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether the specified object property contains a string or a number.- Parameters:
jo
- AnyJsonObject
propertyName
- Any of the properties defined in theJsonObject
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaInteger
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toInteger
parser-function is required to generate the result for this method, thenInteger.parseInt(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonObject
property contained a number, and that number was successfully transformed to aInteger
, then it is returned.
If the object-property was aString
, and thatString
was transformed into aInteger
using either'parser'
- or the default parser, then thatInteger
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
JsonPropMissingException
- If'jo'
does not have a property with the name'propertyName'
and none of these Exception-Flags are set:RETURN_NULL_ON_MISSING
(Abbrev:RN_M
)RETURN_DEFVAL_ON_MISSING
(Abbrev:RD_M
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseObjException
- If theJsonObject
property specified by'propertyName'
contains aJsonString
, this method will attempt to parse thatString
into a JavaInteger
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Integer.parseInt(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullObjException
- If theJsonObject
property specified by'propertyName'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeObjException
- If theJsonObject
property specified by'propertyName'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getINTEGER(JsonObject, String, int, int)
,ReadJSON.parseINTEGER(JsonObject, String, int, int, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ( (! jo.containsKey(propertyName)) || ((t = jo.get(propertyName).getValueType()) == NUMBER) || (t != STRING) ) ? ReadJSON.getINTEGER(jo, propertyName, FLAGS, defaultValue) : ReadJSON.parseINTEGER(jo, propertyName, FLAGS, defaultValue, optionalParser);
-
getLONG
public static java.lang.Long getLONG (JsonObject jo, java.lang.String propertyName, int FLAGS, long defaultValue, java.util.function.Function<java.lang.String,java.lang.Long> optionalParser)
Used to convert aJsonObject
property which can handle either aString
, or aNumber
, and transform that element into a JavaLong
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether the specified object property contains a string or a number.- Parameters:
jo
- AnyJsonObject
propertyName
- Any of the properties defined in theJsonObject
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaLong
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toLong
parser-function is required to generate the result for this method, thenLong.parseLong(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonObject
property contained a number, and that number was successfully transformed to aLong
, then it is returned.
If the object-property was aString
, and thatString
was transformed into aLong
using either'parser'
- or the default parser, then thatLong
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
JsonPropMissingException
- If'jo'
does not have a property with the name'propertyName'
and none of these Exception-Flags are set:RETURN_NULL_ON_MISSING
(Abbrev:RN_M
)RETURN_DEFVAL_ON_MISSING
(Abbrev:RD_M
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseObjException
- If theJsonObject
property specified by'propertyName'
contains aJsonString
, this method will attempt to parse thatString
into a JavaLong
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Long.parseLong(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullObjException
- If theJsonObject
property specified by'propertyName'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeObjException
- If theJsonObject
property specified by'propertyName'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getLONG(JsonObject, String, int, long)
,ReadJSON.parseLONG(JsonObject, String, int, long, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ( (! jo.containsKey(propertyName)) || ((t = jo.get(propertyName).getValueType()) == NUMBER) || (t != STRING) ) ? ReadJSON.getLONG(jo, propertyName, FLAGS, defaultValue) : ReadJSON.parseLONG(jo, propertyName, FLAGS, defaultValue, optionalParser);
-
getSHORT
public static java.lang.Short getSHORT (JsonObject jo, java.lang.String propertyName, int FLAGS, short defaultValue, java.util.function.Function<java.lang.String,java.lang.Short> optionalParser)
Used to convert aJsonObject
property which can handle either aString
, or aNumber
, and transform that element into a JavaShort
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether the specified object property contains a string or a number.- Parameters:
jo
- AnyJsonObject
propertyName
- Any of the properties defined in theJsonObject
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaShort
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toShort
parser-function is required to generate the result for this method, thenShort.parseShort(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonObject
property contained a number, and that number was successfully transformed to aShort
, then it is returned.
If the object-property was aString
, and thatString
was transformed into aShort
using either'parser'
- or the default parser, then thatShort
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
JsonPropMissingException
- If'jo'
does not have a property with the name'propertyName'
and none of these Exception-Flags are set:RETURN_NULL_ON_MISSING
(Abbrev:RN_M
)RETURN_DEFVAL_ON_MISSING
(Abbrev:RD_M
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseObjException
- If theJsonObject
property specified by'propertyName'
contains aJsonString
, this method will attempt to parse thatString
into a JavaShort
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Short.parseShort(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullObjException
- If theJsonObject
property specified by'propertyName'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeObjException
- If theJsonObject
property specified by'propertyName'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getSHORT(JsonObject, String, int, short)
,ReadJSON.parseSHORT(JsonObject, String, int, short, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ( (! jo.containsKey(propertyName)) || ((t = jo.get(propertyName).getValueType()) == NUMBER) || (t != STRING) ) ? ReadJSON.getSHORT(jo, propertyName, FLAGS, defaultValue) : ReadJSON.parseSHORT(jo, propertyName, FLAGS, defaultValue, optionalParser);
-
getBYTE
public static java.lang.Byte getBYTE (JsonObject jo, java.lang.String propertyName, int FLAGS, byte defaultValue, java.util.function.Function<java.lang.String,java.lang.Byte> optionalParser)
Used to convert aJsonObject
property which can handle either aString
, or aNumber
, and transform that element into a JavaByte
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether the specified object property contains a string or a number.- Parameters:
jo
- AnyJsonObject
propertyName
- Any of the properties defined in theJsonObject
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaByte
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toByte
parser-function is required to generate the result for this method, thenByte.parseByte(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonObject
property contained a number, and that number was successfully transformed to aByte
, then it is returned.
If the object-property was aString
, and thatString
was transformed into aByte
using either'parser'
- or the default parser, then thatByte
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
JsonPropMissingException
- If'jo'
does not have a property with the name'propertyName'
and none of these Exception-Flags are set:RETURN_NULL_ON_MISSING
(Abbrev:RN_M
)RETURN_DEFVAL_ON_MISSING
(Abbrev:RD_M
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseObjException
- If theJsonObject
property specified by'propertyName'
contains aJsonString
, this method will attempt to parse thatString
into a JavaByte
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Byte.parseByte(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullObjException
- If theJsonObject
property specified by'propertyName'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeObjException
- If theJsonObject
property specified by'propertyName'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getBYTE(JsonObject, String, int, byte)
,ReadJSON.parseBYTE(JsonObject, String, int, byte, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ( (! jo.containsKey(propertyName)) || ((t = jo.get(propertyName).getValueType()) == NUMBER) || (t != STRING) ) ? ReadJSON.getBYTE(jo, propertyName, FLAGS, defaultValue) : ReadJSON.parseBYTE(jo, propertyName, FLAGS, defaultValue, optionalParser);
-
getDOUBLE
public static java.lang.Double getDOUBLE (JsonObject jo, java.lang.String propertyName, int FLAGS, double defaultValue, java.util.function.Function<java.lang.String,java.lang.Double> optionalParser)
Used to convert aJsonObject
property which can handle either aString
, or aNumber
, and transform that element into a JavaDouble
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether the specified object property contains a string or a number.- Parameters:
jo
- AnyJsonObject
propertyName
- Any of the properties defined in theJsonObject
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaDouble
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toDouble
parser-function is required to generate the result for this method, thenDouble.parseDouble(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonObject
property contained a number, and that number was successfully transformed to aDouble
, then it is returned.
If the object-property was aString
, and thatString
was transformed into aDouble
using either'parser'
- or the default parser, then thatDouble
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
JsonPropMissingException
- If'jo'
does not have a property with the name'propertyName'
and none of these Exception-Flags are set:RETURN_NULL_ON_MISSING
(Abbrev:RN_M
)RETURN_DEFVAL_ON_MISSING
(Abbrev:RD_M
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseObjException
- If theJsonObject
property specified by'propertyName'
contains aJsonString
, this method will attempt to parse thatString
into a JavaDouble
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Double.parseDouble(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullObjException
- If theJsonObject
property specified by'propertyName'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeObjException
- If theJsonObject
property specified by'propertyName'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getDOUBLE(JsonObject, String, int, double)
,ReadJSON.parseDOUBLE(JsonObject, String, int, double, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ( (! jo.containsKey(propertyName)) || ((t = jo.get(propertyName).getValueType()) == NUMBER) || (t != STRING) ) ? ReadJSON.getDOUBLE(jo, propertyName, FLAGS, defaultValue) : ReadJSON.parseDOUBLE(jo, propertyName, FLAGS, defaultValue, optionalParser);
-
getFLOAT
public static java.lang.Float getFLOAT (JsonObject jo, java.lang.String propertyName, int FLAGS, float defaultValue, java.util.function.Function<java.lang.String,java.lang.Float> optionalParser)
Used to convert aJsonObject
property which can handle either aString
, or aNumber
, and transform that element into a JavaFloat
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether the specified object property contains a string or a number.- Parameters:
jo
- AnyJsonObject
propertyName
- Any of the properties defined in theJsonObject
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaFloat
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toFloat
parser-function is required to generate the result for this method, thenFloat.parseFloat(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonObject
property contained a number, and that number was successfully transformed to aFloat
, then it is returned.
If the object-property was aString
, and thatString
was transformed into aFloat
using either'parser'
- or the default parser, then thatFloat
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
JsonPropMissingException
- If'jo'
does not have a property with the name'propertyName'
and none of these Exception-Flags are set:RETURN_NULL_ON_MISSING
(Abbrev:RN_M
)RETURN_DEFVAL_ON_MISSING
(Abbrev:RD_M
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseObjException
- If theJsonObject
property specified by'propertyName'
contains aJsonString
, this method will attempt to parse thatString
into a JavaFloat
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Float.parseFloat(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullObjException
- If theJsonObject
property specified by'propertyName'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeObjException
- If theJsonObject
property specified by'propertyName'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getFLOAT(JsonObject, String, int, float)
,ReadJSON.parseFLOAT(JsonObject, String, int, float, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ( (! jo.containsKey(propertyName)) || ((t = jo.get(propertyName).getValueType()) == NUMBER) || (t != STRING) ) ? ReadJSON.getFLOAT(jo, propertyName, FLAGS, defaultValue) : ReadJSON.parseFLOAT(jo, propertyName, FLAGS, defaultValue, optionalParser);
-
getNUMBER
public static java.lang.Number getNUMBER (JsonObject jo, java.lang.String propertyName, int FLAGS, java.lang.Number defaultValue, java.util.function.Function<java.lang.String,java.lang.Number> optionalParser)
Used to convert aJsonObject
property which can handle either aString
, or aNumber
, and transform that element into a JavaNumber
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether the specified object property contains a string or a number.- Parameters:
jo
- AnyJsonObject
propertyName
- Any of the properties defined in theJsonObject
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaNumber
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toNumber
parser-function is required to generate the result for this method, thennew BigDecimal(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonObject
property contained a number, and that number was successfully transformed to aNumber
, then it is returned.
If the object-property was aString
, and thatString
was transformed into aNumber
using either'parser'
- or the default parser, then thatNumber
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
JsonPropMissingException
- If'jo'
does not have a property with the name'propertyName'
and none of these Exception-Flags are set:RETURN_NULL_ON_MISSING
(Abbrev:RN_M
)RETURN_DEFVAL_ON_MISSING
(Abbrev:RD_M
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseObjException
- If theJsonObject
property specified by'propertyName'
contains aJsonString
, this method will attempt to parse thatString
into a JavaNumber
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (new BigDecimal(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullObjException
- If theJsonObject
property specified by'propertyName'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeObjException
- If theJsonObject
property specified by'propertyName'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getNUMBER(JsonObject, String, int, Number)
,ReadJSON.parseNUMBER(JsonObject, String, int, Number, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ( (! jo.containsKey(propertyName)) || ((t = jo.get(propertyName).getValueType()) == NUMBER) || (t != STRING) ) ? ReadJSON.getNUMBER(jo, propertyName, FLAGS, defaultValue) : ReadJSON.parseNUMBER(jo, propertyName, FLAGS, defaultValue, optionalParser);
-
getBOOLEAN
public static java.lang.Boolean getBOOLEAN (JsonObject jo, java.lang.String propertyName, int FLAGS, boolean defaultValue, java.util.function.Function<java.lang.String,java.lang.Boolean> optionalParser)
Used to convert aJsonObject
property which can handle either aString
, or aNumber
, and transform that element into a JavaBoolean
.
This method simply dispatches to one of theReadJSON
methods, depending upon whether the specified object property contains a string or a number.- Parameters:
jo
- AnyJsonObject
propertyName
- Any of the properties defined in theJsonObject
FLAGS
- The return-value / exception-throw flag constants defined inJFlag
defaultValue
- This is the 'Default Value' returned by this method, if there are any exception or problems converting or extracting the specified number.
The default value is only returned by this method if the appropriate JSON Exception Flag has been passed to the'FLAGS'
parameter! Specifically, if'flags'
were passed'0'
, then this parameter is fully-irrelevant and ignored. The exception flags are listed in classJFlags
AGAIN: If an exception-case is encountered, but the exception-flag for that exception has not been set, then this default-value won't be returned, and that exception will throw instead.optionalParser
- A function wich can map ajava.lang.String
into a JavaBoolean
. This'optionalParser'
is only used if the specified element contains aJsonString
rather than aJsonNumber
. If aJsonNumber
is found, or some other unrelated type, then this parameter is wholly ignored.
NOTE: null may be passed to parameter'optionalParser'
. If null is received, and if it turns out that aString
toBoolean
parser-function is required to generate the result for this method, thenBoolean.parseBoolean(String.trim())
will be used as the default-parser, instead.- Returns:
- If the
JsonObject
property contained a number, and that number was successfully transformed to aBoolean
, then it is returned.
If the object-property was aString
, and thatString
was transformed into aBoolean
using either'parser'
- or the default parser, then thatBoolean
is returned.
In all exception or error cases, parameter'FLAGS'
may indicate that either the default-value be returned, or that null be returned. If the exception-handling flags were not sufficiently set, and an error-case has occured, one of the exceptions listed below is thrown. - Throws:
JsonPropMissingException
- If'jo'
does not have a property with the name'propertyName'
and none of these Exception-Flags are set:RETURN_NULL_ON_MISSING
(Abbrev:RN_M
)RETURN_DEFVAL_ON_MISSING
(Abbrev:RD_M
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonStrParseObjException
- If theJsonObject
property specified by'propertyName'
contains aJsonString
, this method will attempt to parse thatString
into a JavaBoolean
, using either the user-provided'parser'
(if provided), or otherwise, the default-parser (Boolean.parseBoolean(String.trim())
). This exception will throw if parsing theString
generates an exception throw AND none of these Exception-Flags are set:RETURN_NULL_ON_SPEX
(Abbrev:RN_SPEX
)RETURN_DEFVAL_ON_SPEX
(Abbrev:RD_SPEX
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonNullObjException
- If theJsonObject
property specified by'propertyName'
contains Json-Null, rather than aJsonNumber
or aJsonString
, and none of these Exception-Flags are set:RETURN_NULL_ON_NULL
(Abbrev:RN_N
)RETURN_DEFVAL_ON_NULL
(Abbrev:RD_N
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
JsonTypeObjException
- If theJsonObject
property specified by'propertyName'
neither contains aJsonNumber
, nor aJsonString
, AND none of these Exception-Flags are set:RETURN_NULL_ON_WRONG_JSONTYPE
(Abbrev:RN_WT
)RETURN_DEFVAL_ON_WRONG_JSONTYPE
(Abbrev:RD_WT
)RETURN_NULL_ON_ANY_ALL
(Abbrev:RN_AA
)RETURN_DEFVAL_ON_ANY_ALL
(Abbrev:RD_AA
)
- See Also:
ReadJSON.getBOOLEAN(JsonObject, String, int, boolean)
,ReadJSON.parseBOOLEAN(JsonObject, String, int, boolean, Function)
- Code:
- Exact Method Body:
JsonValue.ValueType t; return ( (! jo.containsKey(propertyName)) || ((t = jo.get(propertyName).getValueType()) == TRUE) || (t == FALSE) || (t != STRING) ) ? ReadJSON.getBOOLEAN(jo, propertyName, FLAGS, defaultValue) : ReadJSON.parseBOOLEAN(jo, propertyName, FLAGS, defaultValue, optionalParser);
-
getObject
public static <T> T getObject(JsonArray ja, int index, java.lang.Class<T> c, boolean throwOnNull)
Retrieve aJsonArray
element, and transform it to a JavaObject
(POJO).- Type Parameters:
T
- This is the Java-Type to which theJsonObject
is going to be bound / transformed.
It is important to note that this method is not as smart as you might think. The Java-Type instance that is being created / instantiated must contain a consructor that accepts aJsonObject
as a parameter in order to do the actual bindng. specifically, whatever class is passed to type parameter'T'
, that class must have a single-parameter constructor whose parameter-type isJsonObject
- Parameters:
ja
- Any instance ofJsonArray
index
- A valid index into array parameter'ja'
. In Json (and unlike Java), array element types are not actually checked for consistency - meaning an array may hold many different types! This array-index must contain aJsonObject
c
- This is the class that will bind to theJsonObject
parameter'jo'
.
IMPORTANT: The class'c'
must have a a constructor that accepts aJsonObject
. If this class doesn't have such a constructor, then aJsonBindingException
throws.throwOnNull
- WhenTRUE
is passed to this parameter, if theJsonArray
element located at'index'
contains Json-Null, then this method will throw aJsonNullArrException
. When this parameter isFALSE
, if the specified array element contains Json-Null, then Java-Null is returned.- Returns:
- An instance of Java-Type
Type Parameter T
, if the'ja'
array element located at'index'
uses the appropriate Json-Type -JsonObject
.
If the specified array element contains Json-Null, and'throwOnNull'
has been passedFALSE
, then Java-Null is returned. If the element is null, and'throwOnNull'
isTRUE
, then aJsonNullArrException
throws. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of bounds of'ja'
JsonTypeArrException
- If the array-element (specified by'index'
) does not actually contain aJsonObject
(but rather, some other non-null Json-Type), then this exception throws.JsonNullArrException
- If theJsonArray
element specified by'index'
contains a Json-Null, andTRUE
has been passed to'throwOnNull'
JsonException
- If any of the Java reflection-operations throw exceptions, those exceptions are wrapped into aJsonException
instance, and then re-thrown with the original exception assigned to theThrowable.cause
. ClassJsonException
is an unchecked / Runtime exception, while many of the cause exceptions are not. The possible cause exceptions are listed below.
Description copied from:java.lang.Constructor.newInstance(Object... args)
, JDK 1.8Exception JDK Explanation IllegalAccessException
if this Constructor object is enforcing Java language access control and the underlying constructor is inaccessible. IllegalArgumentException
if the number of actual and formal parameters differ; if an unwrapping conversion for primitive arguments fails; or if, after possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion; if this constructor pertains to an enum type. InstantiationException
if the class that declares the underlying constructor represents an abstract class. InvocationTargetException
if the underlying constructor throws an exception. ExceptionInInitializerError
if the initialization provoked by this method fails. - Code:
- Exact Method Body:
// This will throw an IndexOutOfBoundsException if the index is out of bounds. JsonValue jv = ja.get(index); switch (jv.getValueType()) { case NULL: // This is simple-stuff (not rocket-science). "Type Mapping" Code has to worry // about what the meaning of "null" should be. if (throwOnNull) throw new JsonNullArrException(ja, index, OBJECT, c); else return getObject(null, c); case OBJECT: return getObject((JsonObject) jv, c); // The JsonValue at the specified array-index does not contain a JsonObject. default: throw new JsonTypeArrException(ja, index, OBJECT, jv, c); }
-
getObject
public static <T> T getObject(JsonObject jo, java.lang.String propertyName, java.lang.Class<T> c, boolean isOptional, boolean throwOnNull)
Extract aJsonObject
property, and transform it to a JavaObject
(POJO).- Type Parameters:
T
- This is the Java-Type to which theJsonObject
is going to be bound / transformed.
It is important to note that this method is not as smart as you might think. The Java-Type instance that is being created / instantiated must contain a consructor that accepts aJsonObject
as a parameter in order to do the actual bindng. specifically, whatever class is passed to type parameter'T'
, that class must have a single-parameter constructor whose parameter-type isJsonObject
- Parameters:
jo
- Any instance ofJsonObject
.propertyName
- The name of the JSON property that should be contained within'jo'
. This property will be retrieved and subsequently transformed / converted to Java-TypeType Parameter T
.isOptional
- WhenTRUE
is passed, if'propertyName'
is not actually listed in'jo'
this method shall return Java-Null gracefully. WhenFALSE
is passed, if'jo'
does not have the specified property, aJsonPropMissingException
will throw.
If'jo'
actually has a property named'propertyName'
, then the value passed to this parameter is fully irrelevant.throwOnNull
- WhenTRUE
is passed to this parameter, if theJsonObject
property named'propertyName'
evaluates to Json-Null, then this method will throw aJsonNullObjException
. When this parameter isFALSE
, if the specified property contains Json-Null, then Java-Null is returned.- Returns:
- An instance of Java-Type
Type Parameter T'
, if the'propertyName'
is available inside'jo'
, and that property uses the appropriate Json-Type -JsonObject
.
If the specified property contains Json-Null, and'throwOnNull'
has been passedFALSE
, then Java-Null is returned. If the property is null, and'throwOnNull'
isTRUE
, then aJsonNullObjException
throws.
If the specified property is simply missing, Java-Null is returned, unless'isOptional'
has been passedFALSE
- in which case aJsonPropMissingException
shall be thrown. - Throws:
JsonPropMissingException
- This exception shall throw if the specified property is missing from the'JsonObject'
(parameter'jo'
). This exception throw can be avoided if'TRUE'
is passed to parameter'isOptional'
.JsonTypeObjException
- If the property (specified by'propertyName'
) is extracted, but that property does not actually contain aJsonObject
(but rather, some other non-null Json-Type), then this exception throws.JsonNullObjException
- If theJsonObject
property specified by'propertyName'
contains a Json-Null, andTRUE
has been passed to'throwOnNull'
JsonException
- If any of the Java reflection-operations throw exceptions, those exceptions are wrapped into aJsonException
instance, and then re-thrown with the original exception assigned to theThrowable.cause
. ClassJsonException
is an unchecked / Runtime exception, while many of the cause exceptions are not. The possible cause exceptions are listed below.
Description copied from:java.lang.Constructor.newInstance(Object... args)
, JDK 1.8Exception JDK Explanation IllegalAccessException
if this Constructor object is enforcing Java language access control and the underlying constructor is inaccessible. IllegalArgumentException
if the number of actual and formal parameters differ; if an unwrapping conversion for primitive arguments fails; or if, after possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion; if this constructor pertains to an enum type. InstantiationException
if the class that declares the underlying constructor represents an abstract class. InvocationTargetException
if the underlying constructor throws an exception. ExceptionInInitializerError
if the initialization provoked by this method fails. - Code:
- Exact Method Body:
if (! jo.containsKey(propertyName)) { if (isOptional) return null; throw new JsonPropMissingException(jo, propertyName, OBJECT, c); } JsonValue jv = jo.get(propertyName); switch (jv.getValueType()) { case NULL: // This is simple-stuff (not rocket-science). "Type Mapping" Code has to // worry about what the meaning of "null" should be. if (throwOnNull) throw new JsonNullObjException(jo, propertyName, OBJECT, c); return getObject(null, c); case OBJECT: return getObject((JsonObject) jv, c); // The JsonObject propertydoes not contain a JsonObject. default: throw new JsonTypeObjException(jo, propertyName, OBJECT, jv, c); }
-
getObject
public static <T> T getObject(JsonObject jo, java.lang.Class<T> c)
This class contains a lot of the reason / impetus for writing'ReadJSON'
. This does converts aJsonObject
into a Java-Object. The actual binding must be implemented by the programmer - because the class-type that is passed to this method (parameter'c'
) must have a constructor accepting thisJsonObject
.
IMPORTANT: This method makes no effort to figure out whichJsonObject
properties should be bound to the POJOObject
fields! Note, however, that all of the other one-line type conversion methods in this class is exactly why writing such a constuctor for your Java-Type's should be much easier.
That really is the point of this class.- Type Parameters:
T
- This is the Java-Type to which theJsonObject
is going to be bound / transformed.
It is important to note that this method is not as smart as you might think. The Java-Type instance that is being created / instantiated must contain a consructor that accepts aJsonObject
as a parameter in order to do the actual bindng. specifically, whatever class is passed to type parameter'T'
, that class must have a single-parameter constructor whose parameter-type isJsonObject
- Parameters:
jo
- This may be anyJsonObject
which can be bound to'c'
.
NOTE: This parameter may be null, and if it is, null is passed to the'c'
constructor.c
- This is the class that will bind to theJsonObject
parameter'jo'
.
IMPORTANT: The class'c'
must have a a constructor that accepts aJsonObject
. If this class doesn't have such a constructor, then aJsonBindingException
throws.- Returns:
- An instance of the class
'T'
, which is specified by'c'
- Throws:
JsonException
- If any of the Java reflection-operations throw exceptions, those exceptions are wrapped into aJsonException
instance, and then re-thrown with the original exception assigned to theThrowable.cause
. ClassJsonException
is an unchecked / Runtime exception, while many of the cause exceptions are not. The possible cause exceptions are listed below.
Description copied from:java.lang.Constructor.newInstance(Object... args)
, JDK 1.8Exception JDK Explanation IllegalAccessException
if this Constructor object is enforcing Java language access control and the underlying constructor is inaccessible. IllegalArgumentException
if the number of actual and formal parameters differ; if an unwrapping conversion for primitive arguments fails; or if, after possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion; if this constructor pertains to an enum type. InstantiationException
if the class that declares the underlying constructor represents an abstract class. InvocationTargetException
if the underlying constructor throws an exception. ExceptionInInitializerError
if the initialization provoked by this method fails. - Code:
- Exact Method Body:
Constructor<T> ctor = null; try { // This just gets a "Constructor" using Reflection. The main point is that the // Constructor must have exactly one parameter - and that parameter must have a // type "JsonObject" (basic java.lang.reflect stuff) // //System.out.println("c.getName:():" + c.getName()); ctor = c.getDeclaredConstructor(JsonObject.class); } catch (Exception e) { if (c.getEnclosingClass() != null) { int modifiers = c.getModifiers(); if ((! Modifier.isStatic(modifiers)) || (! Modifier.isPublic(modifiers))) throw new JsonException( "Unable to retrieve POJO Constructor for class: " + "[" + c.getName() + "]\n" + "Your class appears to be a Nested-Class, however it has not been " + "declared public and static. There is no way to retrieve a " + "1-Argument JsonObject Constructor for Nested-Type's unless the " + "type has been declared BOTH static AND public.\n" + "See Exception.getCause() for details.", e ); } else throw new JsonException( "Unable to retrieve POJO Constructor for class: [" + c.getName() + "]\n" + "Do you have a one-argument, public, constructor for this class?\n" + "Does it accept a JsonObject in its parameter list?\n" + "See Exception.getCause() for details.", e ); } // If the user has requested a class that doesn't have that kind of constructor, then // there is no way to build the object. Throw an exception. if (ctor == null) throw new JsonException( "The class which was passed to parameter 'c' [" + c.getName() + "] does not " + "appear to have a constructor with precisely one parameter of type JsonObject." ); // Call that constructor using the parameter 'jo', and return that instance / object try { return ctor.newInstance(jo); } // NOTE: There are *MANY* possible Exception's that may be thrown by reflective // operations like those above. Furthermore, they are *ALL* checked exceptions. // The code below wraps those exceptions into an UN-CHECKED / RuntimeException // (JsonException) catch (Exception e) { throw new JsonException( "Unable to instantiate class: [" + c.getName() + "] using provided " + "Java-Object\n" + "See Exception.getCause() for details.", e ); }
-
-