Class JsonSerializationException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
name.martingeisse.grumpyjson.serialize.JsonSerializationException
- All Implemented Interfaces:
Serializable
This exception type gets thrown when the state of the objects being serialized is not possible to map to JSON.
This can happen if an object is in an inconsistent state (which should have been prevented by the object's class),
or it can happen if the object is in a consistent state that does not have an equivalent representation in JSON.
This exception therefore always indicates a bug. If the object's class allows its state to become inconsistent,
then this should be prevented. On the other hand, if the object's state has no equivalent JSON representation,
then the code that wants to turn it into JSON anyway is faulty. Because it is a bug, and is therefore unexpected,
this class extends RuntimeException, not Exception.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an exception for a single-field error caused by an exception from the serializer.JsonSerializationException(String message) Creates an exception for a single-field error message without a field path.JsonSerializationException(FieldErrorNode fieldErrorNode) Creates an exception for aFieldErrorNodethat wraps one or more actual errors. -
Method Summary
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
JsonSerializationException
Creates an exception for a single-field error message without a field path. This constructor is typically used inJsonSerializer.serialize(Object)at the specific place where an inconsistent or non-JSON-able value was found.- Parameters:
message- the error message- See Also:
-
JsonSerializationException
Creates an exception for a single-field error caused by an exception from the serializer. Application code will rarely use this constructor directly because it can just throw that exception and have the framework wrap it. It is only needed when implementing serializers for custom structured types or custom wrapper types, to implement the catch-and-wrap there.For examples on how this method is useful, see
NullableFieldConverterandOptionalFieldConverter.- Parameters:
cause- the exception to wrap- See Also:
-
JsonSerializationException
Creates an exception for aFieldErrorNodethat wraps one or more actual errors. Application code will usually not call this method directly. It is only needed when implementing serializers for custom structured types, to re-throw after the individual field errors have been combined and field paths applied.For an example on how this method is useful, see
RecordConverterandListConverter.- Parameters:
fieldErrorNode- the node that contains one or more actual errors
-
-
Method Details
-
getFieldErrorNode
Getter for theFieldErrorNodethat holds the actual error(s)- Returns:
- the field error node
-
getMessage
- Overrides:
getMessagein classThrowable
-