Package Torello.Java.JSON
Class ReadPrimJSON
- java.lang.Object
-
- Torello.Java.JSON.ReadPrimJSON
-
public class ReadPrimJSON 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:- 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
Builds on the J2EE Standard Release JSON Parsing Tools by providing additional help with converting JSON Data into Java Primitive-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
Note that this class simply doesn't support any methods for reading achar
. This is because their are just entirely too many possibilities, combinations & options for the appropriate "Default Behavior" when attempting to read a single character of data from any random JSON Data-Type.
Remember that the JSON Specification does not posses any "Single-JSON-Character" Data-Type. Creating some kind of Flag-Controlled Reader for a'char'
that can capably decide what to do would be so overtly verbose, for something so simple, that it isn't worth the effort...- See Also:
Json
,JsonObject
,JsonArray
Hi-Lited Source-Code:- View Here: Torello/Java/JSON/ReadPrimJSON.java
- Open New Browser-Tab: Torello/Java/JSON/ReadPrimJSON.java
File Size: 19,813 Bytes Line Count: 385 '\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
- 14 Method(s), 14 declared static
- 0 Field(s)
- Utilizes the Java-Standard
-
-
Method Summary
int: Retrieve a JsonNumber
and transform it to a Java 'int' PrimitiveModifier and Type Method static int
getInt(JsonArray ja, int index)
static int
getInt(JsonObject jo, String propertyName)
long: Retrieve a JsonNumber
and transform it to a Java 'long' PrimitiveModifier and Type Method static long
getLong(JsonArray ja, int index)
static long
getLong(JsonObject jo, String propertyName)
short: Retrieve a JsonNumber
and transform it to a Java 'short' PrimitiveModifier and Type Method static short
getShort(JsonArray ja, int index)
static short
getShort(JsonObject jo, String propertyName)
byte: Retrieve a JsonNumber
and transform it to a Java 'byte' PrimitiveModifier and Type Method static byte
getByte(JsonArray ja, int index)
static byte
getByte(JsonObject jo, String propertyName)
double: Retrieve a JsonNumber
and transform it to a Java 'double' PrimitiveModifier and Type Method static double
getDouble(JsonArray ja, int index)
static double
getDouble(JsonObject jo, String propertyName)
float: Retrieve a JsonNumber
and transform it to a Java 'float' PrimitiveModifier and Type Method static float
getFloat(JsonArray ja, int index)
static float
getFloat(JsonObject jo, String propertyName)
boolean: Retrieve JsonValue.TRUE
orFALSE
, and transform it to a Java 'boolean' PrimitiveModifier and Type Method static boolean
getBoolean(JsonArray ja, int index)
static boolean
getBoolean(JsonObject jo, String propertyName)
-
-
-
Method Detail
-
getInt
public static int getInt(JsonArray ja, int index)
Retrieve aJsonArray
element, and transform it to an'int'
primitive- 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 aJsonNumber
- Returns:
- An instance of Java-Type
int
, if and only if the array element located at'index'
uses the appropriate Json-Type -JsonNumber
, and that element may be properly mapped to a Javaint
. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of'ja'
JsonTypeArrException
- If the array-element (specified by'index'
) does not actually contain aJsonNumber
(but rather, some other non-null Json-Type), then this exception throws.JsonArithmeticArrException
- Java's implementation ofintValueExact()
throws anArithmeticException
when that method cannot correctly transform / convert the element to a validint
. The thrown-exception is then wrapped into this exception for the purpose of providing a much improved error-message, and convenience fields.JsonNullPrimitiveArrException
- If'index'
specifies an element inside'ja'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitiveint
will not accept 'null' as a value).- See Also:
RJInternal.GET(JsonArray, int, Class, Function)
,JsonNumber.intValueExact()
- Code:
- Exact Method Body:
return GET(ja, index, int.class, JsonNumber::intValueExact);
-
getInt
public static int getInt(JsonObject jo, java.lang.String propertyName)
Extract aJsonObject
property, and transform it to an'int'
primitive- 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-Typeint
.- Returns:
- An instance of Java-Type
int
, if and only if the'propertyName'
is available inside'jo'
, and that property uses the appropriate Json-Type -JsonNumber
. Furthermore, thatJsonNumber
must be assignable to Java Primitive Typeint
, or this method will throw an exception. - Throws:
JsonPropMissingException
- This exception throws if theJsonObject
(parameter'jo'
) does not have any properties with the name'propertyName'
.JsonArithmeticObjException
- Java's implementation ofintValueExact()
throws anArithmeticException
when that method cannot correctly transform / convert the element to a validint
. The thrown-exception is then wrapped into this exception for the purpose of providing a much improved error-message, and convenience fields.JsonTypeObjException
- If the property (specified by'propertyName'
) is extracted, but that property does not actually contain aJsonNumber
(but rather, some other non-null Json-Type), then this exception throws.JsonNullPrimitiveObjException
- If'propertyName'
specifies a property inside'jo'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitiveint
will not accept 'null' as a value).- See Also:
RJInternal.GET(JsonObject, String, Class, Function)
,JsonNumber.intValueExact()
- Code:
- Exact Method Body:
return GET(jo, propertyName, int.class, JsonNumber::intValueExact);
-
getLong
public static long getLong(JsonArray ja, int index)
Retrieve aJsonArray
element, and transform it to a'long'
primitive- 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 aJsonNumber
- Returns:
- An instance of Java-Type
long
, if and only if the array element located at'index'
uses the appropriate Json-Type -JsonNumber
, and that element may be properly mapped to a Javalong
. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of'ja'
JsonTypeArrException
- If the array-element (specified by'index'
) does not actually contain aJsonNumber
(but rather, some other non-null Json-Type), then this exception throws.JsonArithmeticArrException
- Java's implementation oflongValueExact()
throws anArithmeticException
when that method cannot correctly transform / convert the element to a validlong
. The thrown-exception is then wrapped into this exception for the purpose of providing a much improved error-message, and convenience fields.JsonNullPrimitiveArrException
- If'index'
specifies an element inside'ja'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitivelong
will not accept 'null' as a value).- See Also:
RJInternal.GET(JsonArray, int, Class, Function)
,JsonNumber.longValueExact()
- Code:
- Exact Method Body:
return GET(ja, index, long.class, JsonNumber::longValueExact);
-
getLong
public static long getLong(JsonObject jo, java.lang.String propertyName)
Extract aJsonObject
property, and transform it to a'long'
primitive- 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-Typelong
.- Returns:
- An instance of Java-Type
long
, if and only if the'propertyName'
is available inside'jo'
, and that property uses the appropriate Json-Type -JsonNumber
. Furthermore, thatJsonNumber
must be assignable to Java Primitive Typelong
, or this method will throw an exception. - Throws:
JsonPropMissingException
- This exception throws if theJsonObject
(parameter'jo'
) does not have any properties with the name'propertyName'
.JsonArithmeticObjException
- Java's implementation oflongValueExact()
throws anArithmeticException
when that method cannot correctly transform / convert the element to a validlong
. The thrown-exception is then wrapped into this exception for the purpose of providing a much improved error-message, and convenience fields.JsonTypeObjException
- If the property (specified by'propertyName'
) is extracted, but that property does not actually contain aJsonNumber
(but rather, some other non-null Json-Type), then this exception throws.JsonNullPrimitiveObjException
- If'propertyName'
specifies a property inside'jo'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitivelong
will not accept 'null' as a value).- See Also:
RJInternal.GET(JsonObject, String, Class, Function)
,JsonNumber.longValueExact()
- Code:
- Exact Method Body:
return GET(jo, propertyName, long.class, JsonNumber::longValueExact);
-
getShort
public static short getShort(JsonArray ja, int index)
Retrieve aJsonArray
element, and transform it to a'short'
primitive- 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 aJsonNumber
- Returns:
- An instance of Java-Type
short
, if and only if the array element located at'index'
uses the appropriate Json-Type -JsonNumber
, and that element may be properly mapped to a Javashort
. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of'ja'
JsonTypeArrException
- If the array-element (specified by'index'
) does not actually contain aJsonNumber
(but rather, some other non-null Json-Type), then this exception throws.JsonArithmeticArrException
- Java's implementation ofshortValueExact()
throws anArithmeticException
when that method cannot correctly transform / convert the element to a validshort
. The thrown-exception is then wrapped into this exception for the purpose of providing a much improved error-message, and convenience fields.JsonNullPrimitiveArrException
- If'index'
specifies an element inside'ja'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitiveshort
will not accept 'null' as a value).- See Also:
RJInternal.GET(JsonArray, int, Class, Function)
,JsonNumber.bigDecimalValue()
- Code:
- Exact Method Body:
return GET(ja, index, short.class, jn -> jn.bigDecimalValue().shortValueExact());
-
getShort
public static short getShort(JsonObject jo, java.lang.String propertyName)
Extract aJsonObject
property, and transform it to a'short'
primitive- 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-Typeshort
.- Returns:
- An instance of Java-Type
short
, if and only if the'propertyName'
is available inside'jo'
, and that property uses the appropriate Json-Type -JsonNumber
. Furthermore, thatJsonNumber
must be assignable to Java Primitive Typeshort
, or this method will throw an exception. - Throws:
JsonPropMissingException
- This exception throws if theJsonObject
(parameter'jo'
) does not have any properties with the name'propertyName'
.JsonArithmeticObjException
- Java's implementation ofshortValueExact()
throws anArithmeticException
when that method cannot correctly transform / convert the element to a validshort
. The thrown-exception is then wrapped into this exception for the purpose of providing a much improved error-message, and convenience fields.JsonTypeObjException
- If the property (specified by'propertyName'
) is extracted, but that property does not actually contain aJsonNumber
(but rather, some other non-null Json-Type), then this exception throws.JsonNullPrimitiveObjException
- If'propertyName'
specifies a property inside'jo'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitiveshort
will not accept 'null' as a value).- See Also:
RJInternal.GET(JsonObject, String, Class, Function)
,JsonNumber.bigDecimalValue()
- Code:
- Exact Method Body:
return GET(jo, propertyName, short.class, jn -> jn.bigDecimalValue().shortValueExact());
-
getByte
public static byte getByte(JsonArray ja, int index)
Retrieve aJsonArray
element, and transform it to a'byte'
primitive- 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 aJsonNumber
- Returns:
- An instance of Java-Type
byte
, if and only if the array element located at'index'
uses the appropriate Json-Type -JsonNumber
, and that element may be properly mapped to a Javabyte
. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of'ja'
JsonTypeArrException
- If the array-element (specified by'index'
) does not actually contain aJsonNumber
(but rather, some other non-null Json-Type), then this exception throws.JsonArithmeticArrException
- Java's implementation ofbyteValueExact()
throws anArithmeticException
when that method cannot correctly transform / convert the element to a validbyte
. The thrown-exception is then wrapped into this exception for the purpose of providing a much improved error-message, and convenience fields.JsonNullPrimitiveArrException
- If'index'
specifies an element inside'ja'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitivebyte
will not accept 'null' as a value).- See Also:
RJInternal.GET(JsonArray, int, Class, Function)
,JsonNumber.bigDecimalValue()
- Code:
- Exact Method Body:
return GET(ja, index, byte.class, jn -> jn.bigDecimalValue().byteValueExact());
-
getByte
public static byte getByte(JsonObject jo, java.lang.String propertyName)
Extract aJsonObject
property, and transform it to a'byte'
primitive- 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-Typebyte
.- Returns:
- An instance of Java-Type
byte
, if and only if the'propertyName'
is available inside'jo'
, and that property uses the appropriate Json-Type -JsonNumber
. Furthermore, thatJsonNumber
must be assignable to Java Primitive Typebyte
, or this method will throw an exception. - Throws:
JsonPropMissingException
- This exception throws if theJsonObject
(parameter'jo'
) does not have any properties with the name'propertyName'
.JsonArithmeticObjException
- Java's implementation ofbyteValueExact()
throws anArithmeticException
when that method cannot correctly transform / convert the element to a validbyte
. The thrown-exception is then wrapped into this exception for the purpose of providing a much improved error-message, and convenience fields.JsonTypeObjException
- If the property (specified by'propertyName'
) is extracted, but that property does not actually contain aJsonNumber
(but rather, some other non-null Json-Type), then this exception throws.JsonNullPrimitiveObjException
- If'propertyName'
specifies a property inside'jo'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitivebyte
will not accept 'null' as a value).- See Also:
RJInternal.GET(JsonObject, String, Class, Function)
,JsonNumber.bigDecimalValue()
- Code:
- Exact Method Body:
return GET(jo, propertyName, byte.class, jn -> jn.bigDecimalValue().byteValueExact());
-
getDouble
public static double getDouble(JsonArray ja, int index)
Retrieve aJsonArray
element, and transform it to a'double'
primitive
NOTE: If the precision of the providedJsonNumber
contains too much information, the extra digits will simply be lost; no exceptions will throw; and the method shall return a rounded answer - gracefully.
If the magnitude of the number is too large or too small, anArithmeticException
will throw, as explained below.- 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 aJsonNumber
- Returns:
- An instance of Java-Type
double
, if and only if the array element located at'index'
uses the appropriate Json-Type -JsonNumber
, and that element may be properly mapped to a Javadouble
. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of'ja'
JsonTypeArrException
- If the array-element (specified by'index'
) does not actually contain aJsonNumber
(but rather, some other non-null Json-Type), then this exception throws.JsonArithmeticArrException
- Java's implementation ofBigDecimal.doubleValue()
will return an infinity constant (Double.NEGATIVE_INFINITY
orDouble.POSITIVE_INFINITY
) when the magnitude of the returned value is too large to fit inside the Java Typedouble
.
This method checks for the infinity constants, and then proceeds to throw this exception when they are detected.JsonNullPrimitiveArrException
- If'index'
specifies an element inside'ja'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitivedouble
will not accept 'null' as a value).- See Also:
RJInternal.GET(JsonArray, int, Class, Function)
,RJInternal.DOUBLE_WITH_CHECK(JsonNumber)
- Code:
- Exact Method Body:
return GET(ja, index, double.class, RJInternal::DOUBLE_WITH_CHECK);
-
getDouble
public static double getDouble(JsonObject jo, java.lang.String propertyName)
Extract aJsonObject
property, and transform it to a'double'
primitive
NOTE: If the precision of the providedJsonNumber
contains too much information, the extra digits will simply be lost; no exceptions will throw; and the method shall return a rounded answer - gracefully.
If the magnitude of the number is too large or too small, anArithmeticException
will throw, as explained below.- 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-Typedouble
.- Returns:
- An instance of Java-Type
double
, if and only if the'propertyName'
is available inside'jo'
, and that property uses the appropriate Json-Type -JsonNumber
. Furthermore, thatJsonNumber
must be assignable to Java Primitive Typedouble
, or this method will throw an exception. - Throws:
JsonPropMissingException
- This exception throws if theJsonObject
(parameter'jo'
) does not have any properties with the name'propertyName'
.JsonArithmeticObjException
- Java's implementation ofBigDecimal.doubleValue()
will return an infinity constant (Double.NEGATIVE_INFINITY
orDouble.POSITIVE_INFINITY
) when the magnitude of the returned value is too large to fit inside the Java Typedouble
.
This method checks for the infinity constants, and then proceeds to throw this exception when they are detected.JsonTypeObjException
- If the property (specified by'propertyName'
) is extracted, but that property does not actually contain aJsonNumber
(but rather, some other non-null Json-Type), then this exception throws.JsonNullPrimitiveObjException
- If'propertyName'
specifies a property inside'jo'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitivedouble
will not accept 'null' as a value).- See Also:
RJInternal.GET(JsonObject, String, Class, Function)
,RJInternal.DOUBLE_WITH_CHECK(JsonNumber)
- Code:
- Exact Method Body:
return GET(jo, propertyName, double.class, RJInternal::DOUBLE_WITH_CHECK);
-
getFloat
public static float getFloat(JsonArray ja, int index)
Retrieve aJsonArray
element, and transform it to a'float'
primitive
NOTE: If the precision of the providedJsonNumber
contains too much information, the extra digits will simply be lost; no exceptions will throw; and the method shall return a rounded answer - gracefully.
If the magnitude of the number is too large or too small, anArithmeticException
will throw, as explained below.- 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 aJsonNumber
- Returns:
- An instance of Java-Type
float
, if and only if the array element located at'index'
uses the appropriate Json-Type -JsonNumber
, and that element may be properly mapped to a Javafloat
. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of'ja'
JsonTypeArrException
- If the array-element (specified by'index'
) does not actually contain aJsonNumber
(but rather, some other non-null Json-Type), then this exception throws.JsonArithmeticArrException
- Java's implementation ofBigDecimal.floatValue()
will return an infinity constant (Float.NEGATIVE_INFINITY
orFloat.POSITIVE_INFINITY
) when the magnitude of the returned value is too large to fit inside the Java Typefloat
.
This method checks for the infinity constants, and then proceeds to throw this exception when they are detected.JsonNullPrimitiveArrException
- If'index'
specifies an element inside'ja'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitivefloat
will not accept 'null' as a value).- See Also:
RJInternal.GET(JsonArray, int, Class, Function)
,RJInternal.FLOAT_WITH_CHECK(JsonNumber)
- Code:
- Exact Method Body:
return GET(ja, index, float.class, RJInternal::FLOAT_WITH_CHECK);
-
getFloat
public static float getFloat(JsonObject jo, java.lang.String propertyName)
Extract aJsonObject
property, and transform it to a'float'
primitive
NOTE: If the precision of the providedJsonNumber
contains too much information, the extra digits will simply be lost; no exceptions will throw; and the method shall return a rounded answer - gracefully.
If the magnitude of the number is too large or too small, anArithmeticException
will throw, as explained below.- 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-Typefloat
.- Returns:
- An instance of Java-Type
float
, if and only if the'propertyName'
is available inside'jo'
, and that property uses the appropriate Json-Type -JsonNumber
. Furthermore, thatJsonNumber
must be assignable to Java Primitive Typefloat
, or this method will throw an exception. - Throws:
JsonPropMissingException
- This exception throws if theJsonObject
(parameter'jo'
) does not have any properties with the name'propertyName'
.JsonArithmeticObjException
- Java's implementation ofBigDecimal.floatValue()
will return an infinity constant (Float.NEGATIVE_INFINITY
orFloat.POSITIVE_INFINITY
) when the magnitude of the returned value is too large to fit inside the Java Typefloat
.
This method checks for the infinity constants, and then proceeds to throw this exception when they are detected.JsonTypeObjException
- If the property (specified by'propertyName'
) is extracted, but that property does not actually contain aJsonNumber
(but rather, some other non-null Json-Type), then this exception throws.JsonNullPrimitiveObjException
- If'propertyName'
specifies a property inside'jo'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitivefloat
will not accept 'null' as a value).- See Also:
RJInternal.GET(JsonObject, String, Class, Function)
,RJInternal.FLOAT_WITH_CHECK(JsonNumber)
- Code:
- Exact Method Body:
return GET(jo, propertyName, float.class, RJInternal::FLOAT_WITH_CHECK);
-
getBoolean
public static boolean getBoolean(JsonArray ja, int index)
Retrieve aJsonArray
element, and transform it to a'boolean'
primitive- 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 aJSON-BOOLEAN
- Returns:
- An instance of Java-Type
boolean
, if and only if the array element located at'index'
uses the appropriate Json-Type -JSON-BOOLEAN
, and that element may be properly mapped to a Javaboolean
. - Throws:
java.lang.IndexOutOfBoundsException
- If'index'
is out of the bounds of'ja'
JsonTypeArrException
- If the array-element (specified by'index'
) does not actually contain aJSON-BOOLEAN
(but rather, some other non-null Json-Type), then this exception throws.JsonNullPrimitiveArrException
- If'index'
specifies an element inside'ja'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitiveboolean
will not accept 'null' as a value).- See Also:
ReadBoxedJSON.getBoolean(JsonArray, int)
- Code:
- Exact Method Body:
// This method (defined below) allows for null-returns, but "getBoolean" does not. // "getBOOLEAN" will only return null if the actual array location 'index' actually has // the word 'null' listed. Boolean ret = ReadBoxedJSON.getBoolean(ja, index); // In that case, throw the Null-Primitive Exception if (ret == null) throw new JsonNullPrimitiveArrException (ja, index, TRUE, boolean.class); return ret;
-
getBoolean
public static boolean getBoolean(JsonObject jo, java.lang.String propertyName)
Extract aJsonObject
property, and transform it to a'boolean'
primitive- 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-Typeboolean
.- Returns:
- An instance of Java-Type
boolean
, if and only if the'propertyName'
is available inside'jo'
, and that property uses the appropriate Json-Type -JSON-BOOLEAN
. Furthermore, thatJSON-BOOLEAN
must be assignable to Java Primitive Typeboolean
, or this method will throw an exception. - Throws:
JsonPropMissingException
- This exception throws if theJsonObject
(parameter'jo'
) does not have any properties with the name'propertyName'
.JsonTypeObjException
- If the property (specified by'propertyName'
) is extracted, but that property does not actually contain aJSON-BOOLEAN
(but rather, some other non-null Json-Type), then this exception throws.JsonNullPrimitiveObjException
- If'propertyName'
specifies a property inside'jo'
that has been assigned Json-Null, then this exception will throw. (Unlike Json, in Java a Primitiveboolean
will not accept 'null' as a value).- See Also:
ReadBoxedJSON.getBoolean(JsonObject, String, boolean)
- Code:
- Exact Method Body:
// Since 'false' is passed, a null return-value will mean that the property was actually // set to null in the JsonObject itself. (It *IS NOT* missing, it is present, but rather // declared null) Boolean ret = ReadBoxedJSON.getBoolean(jo, propertyName, false); if (ret == null) throw new JsonNullPrimitiveObjException (jo, propertyName, TRUE, boolean.class); // NOTE: Java's Type-Stuff can automatically convert Boolean -> boolean else return ret;
-
-