Package Torello.JSON
Class InvalidClassException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- Torello.JSON.InvalidClassException
-
- All Implemented Interfaces:
java.io.Serializable
public class InvalidClassException extends java.lang.RuntimeException
Used for Read Json method that attempt to build a Java POJO, but fail due to an inability to extract a valid constructor from the object. When using a class' constructor as a builder, the required constructor must be one which accepts only one parameter. That parameter must be of typeJsonObject.- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/JSON/InvalidClassException.java
- Open New Browser-Tab: Torello/JSON/InvalidClassException.java
File Size: 5,822 Bytes Line Count: 139 '\n' Characters Found
-
-
Field Summary
Fields Modifier and Type Field static longserialVersionUID
-
Constructor Summary
Constructors Constructor InvalidClassException()InvalidClassException(String message)InvalidClassException(String message, Throwable cause)InvalidClassException(Throwable cause)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method static <T> Constructor<T>check(Class<T> c)
-
-
-
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;
-
-
Constructor Detail
-
InvalidClassException
public InvalidClassException()
Constructs aInvalidClassExceptionwith no detail message.
-
InvalidClassException
public InvalidClassException(java.lang.String message)
Constructs aInvalidClassExceptionwith the specified detail message.- Parameters:
message- the detail message.
-
InvalidClassException
public InvalidClassException(java.lang.String message, java.lang.Throwable cause)
Constructs a newInvalidClassExceptionwith 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.)
-
InvalidClassException
public InvalidClassException(java.lang.Throwable cause)
Constructs a newInvalidClassExceptionwith 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.)
-
-
Method Detail
-
check
public static <T> java.lang.reflect.Constructor<T> check (java.lang.Class<T> c)
Extracts a validjava.lang.reflect.Constructorinstance for a constructor that accepts one arguement of typeJsonObject.
Throws if such an instance ofConstructorcannot be found.- Throws:
java.lang.NullPointerException- throws if parameter'c'is nullInvalidClassException- throws if any errors occur when extracting the instance ofjava.lang.reflect.Constructor. This method excepts & attempts to extract a one argument constructor whose sole arguement is of typeJsonObject.- Code:
- Exact Method Body:
final Constructor<T> ctor; Objects.requireNonNull(c, "The Class<T> parameter 'c' has been passed 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 InvalidClassException( "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 InvalidClassException( "There was a problem retrieving a one-argument, public, constructor for the " + "class you wish to instantiate. See Exception.getCause() for details.", e ); } else throw new InvalidClassException( "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 InvalidClassException( "The class which was passed to parameter 'c' [" + c.getName() + "] does not " + "appear to have a constructor with precisely one parameter of type JsonObject. " + "c.getDeclaredConstructor(JsonObject.class) has returned null." ); return ctor;
-
-