Class JsonSerializationException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
name.martingeisse.grumpyjson.serialize.JsonSerializationException
All Implemented Interfaces:
Serializable

public class JsonSerializationException extends RuntimeException
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 Details

    • JsonSerializationException

      public JsonSerializationException(String message)
      Creates an exception for a single-field error message without a field path. This constructor is typically used in JsonSerializer.serialize(Object) at the specific place where an inconsistent or non-JSON-able value was found.
      Parameters:
      message - the error message
      See Also:
    • JsonSerializationException

      public JsonSerializationException(Exception cause)
      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 NullableFieldConverter and OptionalFieldConverter.

      Parameters:
      cause - the exception to wrap
      See Also:
    • JsonSerializationException

      public JsonSerializationException(FieldErrorNode fieldErrorNode)
      Creates an exception for a FieldErrorNode that 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 RecordConverter and ListConverter.

      Parameters:
      fieldErrorNode - the node that contains one or more actual errors
  • Method Details