Package Torello.JSON
Class JsonBindingException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- javax.json.JsonException
-
- Torello.JSON.JsonBindingException
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
JsonBindingArrException,JsonBindingObjException
public abstract class JsonBindingException extends JsonException
The parent class of all Json Exceptions in this package. This class contains several convenience fields that will be auto-populated by any method inside Java HTML that would throw this exception, or any of this exception's descendant classes.
NOTE: This class is abstract, and cannot be instantiated.
The following'final'Convenience Fields are exported by this Exception Class:Field Field Type errorSourceJsonStructJsonStructureexpectedJsonTypeJsonValue.ValueTypemethodReturnJavaTypejava.lang.ClassvalueRetrievedJsonValue- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/JSON/JsonBindingException.java
- Open New Browser-Tab: Torello/JSON/JsonBindingException.java
File Size: 14,814 Bytes Line Count: 342 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field static longserialVersionUID'final'Exception Convenience FieldsModifier and Type Field JsonStructureerrorSourceJsonStructJsonValue.ValueTypeexpectedJsonTypeClass<?>methodReturnJavaTypeJsonValuevalueRetrieved
-
Constructor Summary
Constructors Constructor JsonBindingException(String message, Throwable cause, JsonStructure errorSourceJsonStruct, JsonValue.ValueType expectedJsonType, JsonValue valueRetrieved, Class<?> methodReturnJavaType)JsonBindingException(String message, JsonStructure errorSourceJsonStruct, JsonValue.ValueType expectedJsonType, JsonValue valueRetrieved, Class<?> methodReturnJavaType)JsonBindingException(Throwable cause, JsonStructure errorSourceJsonStruct, JsonValue.ValueType expectedJsonType, JsonValue valueRetrieved, Class<?> methodReturnJavaType)JsonBindingException(JsonStructure errorSourceJsonStruct, JsonValue.ValueType expectedJsonType, JsonValue valueRetrieved, Class<?> methodReturnJavaType)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method protected static StringBASE_MESSAGE(JsonStructure errorSourceJsonStruct, JsonValue.ValueType expectedJsonType, JsonValue valueRetrieved, Class<?> methodReturnJavaType, Throwable... causes)
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable. Using theSerializableImplementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.
Note that Java'sjava.lang.Exceptionandjava.lang.Errorclasses implement theSerializable interface, and a warning-free build expects this field be defined here.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
public static final long serialVersionUID = 1;
-
errorSourceJsonStruct
public final JsonStructure errorSourceJsonStruct
This field is provided to the user as a matter of convenience. All instances of thisExceptionought to guarantee that when an instance is thrown - any & all "Convenience Fields" have been properly set.
If this package is extended, or if this exception is used elsewhere, try to remember to not to accidentally leave this field null when using this class' constructors.
In Summary:
All this is really trying to explain is that, when debugging your code, if in the analysis of a particularException, that analysis causes another exception throw (NullPointerException) - BECAUSE THIS CONVENIENCE FIELD WAS LEFT NULL - you would likely get pretty angry.
This contains the actualJsonStructure(which should either be an instance ofJsonObjectorJsonArray) which contained the array-element or object-property that has caused this exception throw.- Code:
- Exact Field Declaration Expression:
public final JsonStructure errorSourceJsonStruct;
-
expectedJsonType
public final JsonValue.ValueType expectedJsonType
This field is provided to the user as a matter of convenience. All instances of thisExceptionought to guarantee that when an instance is thrown - any & all "Convenience Fields" have been properly set.
If this package is extended, or if this exception is used elsewhere, try to remember to not to accidentally leave this field null when using this class' constructors.
In Summary:
All this is really trying to explain is that, when debugging your code, if in the analysis of a particularException, that analysis causes another exception throw (NullPointerException) - BECAUSE THIS CONVENIENCE FIELD WAS LEFT NULL - you would likely get pretty angry.
This contains the expected type which ought to have been found at the user-specifiedJsonArrayorJsonObjectlocation. Since both of these kinds ofJsonStructureare only allowed to have Json-Type's; therefore this field's declared type isJsonValue.ValueType.
ASIDE: The enumJsonValue.ValueTypehas two enum-constants which represent the Json-Type 'Boolean'. As a result, there are two possible values to which this field could be assigned to symbolize a Json Boolean Type (JsonValue.ValueType.FALSEandJsonValue.ValueType.TRUE). However, in Java HTML, a Json-Boolean Type will always be represented using theTRUEenum-constant.- Code:
- Exact Field Declaration Expression:
public final JsonValue.ValueType expectedJsonType;
-
valueRetrieved
public final JsonValue valueRetrieved
This field is provided to the user as a matter of convenience. All instances of thisExceptionought to guarantee that when an instance is thrown - any & all "Convenience Fields" have been properly set.
If this package is extended, or if this exception is used elsewhere, try to remember to not to accidentally leave this field null when using this class' constructors.
In Summary:
All this is really trying to explain is that, when debugging your code, if in the analysis of a particularException, that analysis causes another exception throw (NullPointerException) - BECAUSE THIS CONVENIENCE FIELD WAS LEFT NULL - you would likely get pretty angry.
This is the value retrieved from theJsonArrayorJsonObject. If the value was not present or unavailable, then this parameter will, indeed, evaulated to Java-Null. If Json-Null was retrieved, then this parameter will containJsonValue.NULL.- Code:
- Exact Field Declaration Expression:
public final JsonValue valueRetrieved;
-
methodReturnJavaType
public final java.lang.Class<?> methodReturnJavaType
This field is provided to the user as a matter of convenience. All instances of thisExceptionought to guarantee that when an instance is thrown - any & all "Convenience Fields" have been properly set.
If this package is extended, or if this exception is used elsewhere, try to remember to not to accidentally leave this field null when using this class' constructors.
In Summary:
All this is really trying to explain is that, when debugging your code, if in the analysis of a particularException, that analysis causes another exception throw (NullPointerException) - BECAUSE THIS CONVENIENCE FIELD WAS LEFT NULL - you would likely get pretty angry.
This specifies return type (as an instance ofjava.lang.Class<T>that is used by the method which has thrown this exception. This is the Java-Type to which the Json-Type was going to be assigned.- Code:
- Exact Field Declaration Expression:
public final Class<?> methodReturnJavaType;
-
-
Constructor Detail
-
JsonBindingException
public JsonBindingException(JsonStructure errorSourceJsonStruct, JsonValue.ValueType expectedJsonType, JsonValue valueRetrieved, java.lang.Class<?> methodReturnJavaType)
Constructs aJsonBindingExceptionwith no detail message.
-
JsonBindingException
public JsonBindingException(java.lang.String message, JsonStructure errorSourceJsonStruct, JsonValue.ValueType expectedJsonType, JsonValue valueRetrieved, java.lang.Class<?> methodReturnJavaType)
Constructs aJsonBindingExceptionwith the specified detail message, and user-provided convenience-field values.- Parameters:
message- the detail message.errorSourceJsonStruct- TheJsonStructurefrom which the element or property (dependent upon which subclass is inheriting this exception), is being retrieved / extracted.expectedJsonType- This is the Json-Type that was expected to be retrieved fromJsonArray.valueRetrieved- This is theJsonValuethat was extracted from theJsonArraywhich caused an exception. Note that if the entity did not exist, then this parameter will be Java-Null. If Json-Null was found, then this parameter should beJsonValue.NULLmethodReturnJavaType- ClassReadJSONwill always provide the ultimate Java-Type that is to be returned by the method where this exception is being thrown.
-
JsonBindingException
public JsonBindingException(java.lang.String message, java.lang.Throwable cause, JsonStructure errorSourceJsonStruct, JsonValue.ValueType expectedJsonType, JsonValue valueRetrieved, java.lang.Class<?> methodReturnJavaType)
Constructs a newJsonBindingExceptionwith the specified detail message and cause.
NOTE:
The detail message associated with cause is not automatically incorporated into this exception's detail message.- Parameters:
message- The detail message (which is saved for later retrieval by theThrowable.getMessage()method).cause- the cause (which is saved for later retrieval by theThrowable.getCause()method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)errorSourceJsonStruct- TheJsonStructurefrom which the element or property (dependent upon which subclass is inheriting this exception), is being retrieved / extracted.expectedJsonType- This is the Json-Type that was expected to be retrieved fromJsonArray.valueRetrieved- This is theJsonValuethat was extracted from theJsonArraywhich caused an exception. Note that if the entity did not exist, then this parameter will be Java-Null. If Json-Null was found, then this parameter should beJsonValue.NULLmethodReturnJavaType- ClassReadJSONwill always provide the ultimate Java-Type that is to be returned by the method where this exception is being thrown.
-
JsonBindingException
public JsonBindingException(java.lang.Throwable cause, JsonStructure errorSourceJsonStruct, JsonValue.ValueType expectedJsonType, JsonValue valueRetrieved, java.lang.Class<?> methodReturnJavaType)
Constructs a newJsonBindingExceptionwith the specified cause and a detail message of(cause==null ? null : cause.toString())(which typically contains the class and detail message of cause).
This constructor is useful for exceptions that are little more than wrappers for other throwables.- Parameters:
cause- The cause (which is saved for later retrieval by theThrowable.getCause()method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)errorSourceJsonStruct- TheJsonStructurefrom which the element or property (dependent upon which subclass is inheriting this exception), is being retrieved / extracted.expectedJsonType- This is the Json-Type that was expected to be retrieved fromJsonArray.valueRetrieved- This is theJsonValuethat was extracted from theJsonArraywhich caused an exception. Note that if the entity did not exist, then this parameter will be Java-Null. If Json-Null was found, then this parameter should beJsonValue.NULLmethodReturnJavaType- ClassReadJSONwill always provide the ultimate Java-Type that is to be returned by the method where this exception is being thrown.
-
-
Method Detail
-
BASE_MESSAGE
protected static java.lang.String BASE_MESSAGE (JsonStructure errorSourceJsonStruct, JsonValue.ValueType expectedJsonType, JsonValue valueRetrieved, java.lang.Class<?> methodReturnJavaType, java.lang.Throwable... causes)
A simple helper method for printing consistent error messages using the input-data convenience fields.- Parameters:
errorSourceJsonStruct- TheJsonStructurefrom which the element or property (dependent upon which subclass is inheriting this exception), is being retrieved / extracted.expectedJsonType- This is the Json-Type that was expected to be retrieved fromJsonArray.valueRetrieved- This is theJsonValuethat was extracted from theJsonArraywhich caused an exception. Note that if the entity did not exist, then this parameter will be Java-Null. If Json-Null was found, then this parameter should beJsonValue.NULLmethodReturnJavaType- ClassReadJSONwill always provide the ultimate Java-Type that is to be returned by the method where this exception is being thrown.causes- Optional Parameter. At most 1 cause is printed.- Returns:
- The error message
String. - Code:
- Exact Method Body:
// After much argument with Chat-GPT, I have decided to encode the following line // right here final String srcJsonAsStr = (errorSourceJsonStruct == null) // This means that the user's null JO or JA has trickled all the way here, before // and NPE has thrown. The NPE should have thrown the minute that ReadJSON attempts // to extract an element from an array or object that is null. // // I don't use "Assert Statements", and I don't know why, but that's how this works. // This is just a glorified "Assert Statement". This should never happen. The value // passed to "errorSourceJsonStruct" is just the JsonArray or JsonObject that the user // requested for data extraction. If that were null, an actual NPE should throw by the // second or third line of the method. ? ( '\n' + "\t*** ERROR: The Source Json-Structure you have passed is, itself, null\n" + "\t*** HOWEVER: My code should have already thrown an NPE, the moment you passed " + "null\n"+ "\t*** SORRY!" ) : errorSourceJsonStruct.getClass().getSimpleName(); return "Problems Binding Json\n" + CAUSE_MESSAGE(causes) + "\tFound In JsonStructure: " + ABBREV_STRUCT(errorSourceJsonStruct) + "\n" + "\tJsonStructure SubClass: " + srcJsonAsStr + "\n" + "\tExpected Json-Type: " + JT_STR(expectedJsonType) + "\n" + "\tContained JsonValue: " + ABBREV_VAL(valueRetrieved) + "\n" + "\tHaving Actual Json-Type: " + JT_STR((valueRetrieved != null) ? valueRetrieved.getValueType() : null ) + "\n" + RET_TYPE_STR(methodReturnJavaType) + '\n';
-
-