Class JacksonException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
JacksonIOException, StreamConstraintsException, StreamReadException, StreamWriteException

public class JacksonException extends RuntimeException
Base class for all Jackson-produced checked exceptions.

Note that in Jackson 2.x this exception extended IOException but in 3.x RuntimeException

See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • withCause

      public JacksonException withCause(Throwable cause)
    • clearLocation

      public JacksonException clearLocation()
      Method that allows to remove context information from this exception's message. Useful when you are parsing security-sensitive data and don't want original data excerpts to be present in Jackson parser error messages.
      Returns:
      This exception instance to allow call chaining
    • wrapWithPath

      public static JacksonException wrapWithPath(Throwable src, Object refFrom, String refPropertyName)
      Method that can be called to either create a new JacksonException (if underlying exception is not a JacksonException), or augment given exception with given path/reference information. This version of method is called when the reference is through a non-indexed object, such as a Map or POJO/bean.
    • wrapWithPath

      public static JacksonException wrapWithPath(Throwable src, Object refFrom, int index)
      Method that can be called to either create a new JacksonException (if underlying exception is not a JacksonException), or augment given exception with given path/reference information. This version of method is called when the reference is through an index, which happens with arrays and Collections.
    • wrapWithPath

      public static JacksonException wrapWithPath(Throwable src, JacksonException.Reference ref)
      Method that can be called to either create a new JacksonException (if underlying exception is not a JacksonException), or augment given exception with given path/reference information.
    • wrapWithPath

    • _exceptionMessage

      public static String _exceptionMessage(Throwable t)
    • prependPath

      public JacksonException prependPath(Object referrer, String propertyName)
      Method called to prepend a reference information in front of current path
    • prependPath

      public JacksonException prependPath(Object referrer, int index)
      Method called to prepend a reference information in front of current path
    • prependPath

    • getPath

      public List<JacksonException.Reference> getPath()
      Method for accessing full structural path within type hierarchy down to problematic property.
    • getPathReference

      public String getPathReference()
      Method for accessing description of path that lead to the problem that triggered this exception
    • getPathReference

      public StringBuilder getPathReference(StringBuilder sb)
    • getLocation

      public TokenStreamLocation getLocation()
      Accessor for location information related to position within input or output (depending on operation), if available; if not available may return TokenStreamLocation.NA (but never null).

      Accuracy of location information depends on backend (format) as well as (in some cases) operation being performed.

      Returns:
      Location in input or output that triggered the problem reported, if available; null otherwise.
    • getOriginalMessage

      public String getOriginalMessage()
      Method that allows accessing the original "message" argument, without additional decorations (like location information) that overridden getMessage() adds.
      Returns:
      Original, unmodified message argument used to construct this exception instance
    • processor

      public Object processor()
      Method that allows accessing underlying processor that triggered this exception; typically either JsonParser or JsonGenerator for exceptions that originate from streaming API, but may be other types when thrown by databinding.

      Note that it is possible that null may be returned if code throwing exception either has no access to the processor; or has not been retrofitted to set it; this means that caller needs to take care to check for nulls. Subtypes override this method with co-variant return type, for more type-safe access.

      NOTE: In Jackson 2.x, accessor was getProcessor(): in 3.0 changed to non-getter to avoid having to annotate for serialization.

      Returns:
      Originating processor, if available; null if not.
    • messageSuffix

      protected String messageSuffix()
      Accessor that sub-classes can override to append additional information right after the main message, but before source location information.

      NOTE: In Jackson 2.x, accessor was getMessageSuffix(): in 3.0 changed to non-getter to indicate it is not a "regular" getter (although it would not be serialized anyway due to lower visibility).

      Returns:
      Message suffix configured to be used, if any; null if none
    • getLocalizedMessage

      public String getLocalizedMessage()
      Overrides:
      getLocalizedMessage in class Throwable
    • getMessage

      public String getMessage()
      Method is overridden so that we can properly inject description of problem path, if such is defined.
      Overrides:
      getMessage in class Throwable
    • _buildMessage

      protected String _buildMessage()
      Default method overridden so that we can add location information
      Returns:
      Message constructed based on possible optional prefix; explicit message passed to constructor as well trailing location description (separate from message by linefeed)
    • toString

      public String toString()
      Overrides:
      toString in class Throwable
    • _appendReferenceChain

      protected StringBuilder _appendReferenceChain(StringBuilder sb)
    • _appendPathDesc

      protected StringBuilder _appendPathDesc(StringBuilder sb)