Top Description Inners Fields Constructors Methods
tools.jackson.core

public Class JacksonException

extends RuntimeException
Class Inheritance
Known Direct Subclasses
tools.jackson.core.exc.JacksonIOException, tools.jackson.core.exc.StreamConstraintsException, tools.jackson.core.exc.StreamReadException, tools.jackson.core.exc.StreamWriteException
Imports
java.io.Closeable, .Serializable, java.lang.reflect.InvocationTargetException, java.util.*, java.util.function.BiFunction

Base class for all Jackson-produced checked exceptions.

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
JacksonException.Reference

Simple bean class used to contain references.

Field Summary

Modifier and TypeField and Description
protected TokenStreamLocation
protected LinkedList<JacksonException.Reference>
_path

Path through which problem that triggering throwing of this exception was reached.

protected transient Closeable
_processor

Underlying processor (JsonParser or JsonGenerator), if known.

private static final int
MAX_REFS_TO_LIST

Let's limit length of reference chain, to limit damage in cases of infinite recursion.

private static final long

Constructor Summary

AccessConstructor and Description
protected
protected
protected
protected
protected
JacksonException(Closeable processor, Throwable rootCause)

protected
protected
protected
JacksonException(Closeable processor, String msg, Throwable problem)

protected

Method Summary

Modifier and TypeMethod and Description
protected StringBuilder
protected StringBuilder
protected String

Returns:

Message constructed based on possible optional prefix; explicit message passed to constructor as well trailing location description (separate from message by linefeed)
_buildMessage
()

Default method overridden so that we can add location information

public static String
private static TokenStreamLocation
public JacksonException

Returns:

This exception instance to allow call chaining
clearLocation
()

Method that allows to remove context information from this exception's message.

public String
getLocalizedMessage()

Overrides java.lang.Throwable.getLocalizedMessage.

Creates a localized description of this throwable.

public TokenStreamLocation

Returns:

Location in input or output that triggered the problem reported, if available; null otherwise.
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).

public String
getMessage()

Overrides java.lang.Throwable.getMessage.

Method is overridden so that we can properly inject description of problem path, if such is defined.

public String

Returns:

Original, unmodified message argument used to construct this exception instance
getOriginalMessage
()

Method that allows accessing the original "message" argument, without additional decorations (like location information) that overridden getMessage adds.

public List<JacksonException.Reference>
getPath()

Method for accessing full structural path within type hierarchy down to problematic property.

public String
getPathReference()

Method for accessing description of path that lead to the problem that triggered this exception

public StringBuilder
protected String

Returns:

Message suffix configured to be used, if any; null if none
messageSuffix
()

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

public JacksonException
prependPath(Object referrer, String propertyName)

Method called to prepend a reference information in front of current path

public JacksonException
prependPath(Object referrer, int index)

Method called to prepend a reference information in front of current path

public JacksonException
public Object

Returns:

Originating processor, if available; null if not.
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.

public String
toString()

Overrides java.lang.Throwable.toString.

Returns a short description of this throwable.

public JacksonException
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.

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.

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.

public static JacksonException

Field Detail

_locationback to summary
protected TokenStreamLocation _location
_pathback to summary
protected LinkedList<JacksonException.Reference> _path

Path through which problem that triggering throwing of this exception was reached.

_processorback to summary
protected transient Closeable _processor

Underlying processor (JsonParser or JsonGenerator), if known.

Note

typically not serializable hence transient

MAX_REFS_TO_LISTback to summary
private static final int MAX_REFS_TO_LIST

Let's limit length of reference chain, to limit damage in cases of infinite recursion. Use maximum nesting limit allowed for reads.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.RuntimeException.serialVersionUID.

Constructor Detail

JacksonExceptionback to summary
protected JacksonException(String msg)
JacksonExceptionback to summary
protected JacksonException(Throwable rootCause)
JacksonExceptionback to summary
protected JacksonException(String msg, Throwable rootCause)
JacksonExceptionback to summary
protected JacksonException(String msg, TokenStreamLocation loc, Throwable rootCause)
JacksonExceptionback to summary
protected JacksonException(Closeable processor, Throwable rootCause)
JacksonExceptionback to summary
protected JacksonException(Closeable processor, String msg, TokenStreamLocation loc, Throwable rootCause)
JacksonExceptionback to summary
protected JacksonException(Closeable processor, String msg)
JacksonExceptionback to summary
protected JacksonException(Closeable processor, String msg, Throwable problem)
JacksonExceptionback to summary
protected JacksonException(Closeable processor, String msg, TokenStreamLocation loc)

Method Detail

_appendPathDescback to summary
protected StringBuilder _appendPathDesc(StringBuilder sb)
_appendReferenceChainback to summary
protected StringBuilder _appendReferenceChain(StringBuilder sb)
_buildMessageback to summary
protected String _buildMessage()

Default method overridden so that we can add location information

Returns:String

Message constructed based on possible optional prefix; explicit message passed to constructor as well trailing location description (separate from message by linefeed)

_exceptionMessageback to summary
public static String _exceptionMessage(Throwable t)
_nonNullLocationback to summary
private static TokenStreamLocation _nonNullLocation(TokenStreamLocation loc)
clearLocationback to summary
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:JacksonException

This exception instance to allow call chaining

getLocalizedMessageback to summary
public String getLocalizedMessage()

Overrides java.lang.Throwable.getLocalizedMessage.

Doc from java.lang.Throwable.getLocalizedMessage.

Creates a localized description of this throwable. Subclasses may override this method in order to produce a locale-specific message. For subclasses that do not override this method, the default implementation returns the same result as getMessage().

Annotations
@Override
getLocationback to summary
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:TokenStreamLocation

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

getMessageback to summary
public String getMessage()

Overrides java.lang.Throwable.getMessage.

Method is overridden so that we can properly inject description of problem path, if such is defined.

Annotations
@Override
getOriginalMessageback to summary
public String getOriginalMessage()

Method that allows accessing the original "message" argument, without additional decorations (like location information) that overridden getMessage adds.

Returns:String

Original, unmodified message argument used to construct this exception instance

getPathback to summary
public List<JacksonException.Reference> getPath()

Method for accessing full structural path within type hierarchy down to problematic property.

getPathReferenceback to summary
public String getPathReference()

Method for accessing description of path that lead to the problem that triggered this exception

getPathReferenceback to summary
public StringBuilder getPathReference(StringBuilder sb)
messageSuffixback to summary
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:String

Message suffix configured to be used, if any; null if none

prependPathback to summary
public JacksonException prependPath(Object referrer, String propertyName)

Method called to prepend a reference information in front of current path

prependPathback to summary
public JacksonException prependPath(Object referrer, int index)

Method called to prepend a reference information in front of current path

prependPathback to summary
public JacksonException prependPath(JacksonException.Reference r)
processorback to summary
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:Object

Originating processor, if available; null if not.

toStringback to summary
public String toString()

Overrides java.lang.Throwable.toString.

Doc from java.lang.Throwable.toString.

Returns a short description of this throwable. The result is the concatenation of:

  • the name of the class of this object
  • ": " (a colon and a space)
  • the result of invoking this object's getLocalizedMessage method
If getLocalizedMessage returns null, then just the class name is returned.
Annotations
@Override
withCauseback to summary
public JacksonException withCause(Throwable cause)
wrapWithPathback to summary
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.

wrapWithPathback to summary
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.

wrapWithPathback to summary
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.

Annotations
@SuppressWarnings:resource
wrapWithPathback to summary
public static JacksonException wrapWithPath(Throwable src, JacksonException.Reference ref, BiFunction<String, Throwable, JacksonException> ctor)
tools.jackson.core back to summary

public Class JacksonException.Reference

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Simple bean class used to contain references. References can be added to indicate execution/reference path that lead to the problem that caused this exception to be thrown.
Since
3.0 (in 2.x was part of databind-level exceptions only)

Field Summary

Modifier and TypeField and Description
protected String
_desc

Lazily-constructed description of this instance; needed mostly to allow JDK serialization to work in case where _from is non-serializable (and has to be dropped) but we still want to pass actual description along.

protected transient Object
protected int
_index

Index within a Collection instance that contained the reference; used if index is relevant and available.

protected String
_propertyName

Name of property (for POJO) or key (for Maps) that is part of the reference.

private static final long

Constructor Summary

AccessConstructor and Description
protected
Reference()

Default constructor for deserialization purposes

public
public
Reference(Object from, String propertyName)

public
Reference(Object from, int index)

Method Summary

Modifier and TypeMethod and Description
public Object
from()

Object through which reference was resolved.

public String
public int
public String
pack-priv void
pack-priv void
setIndex(int ix)

pack-priv void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv Object
writeReplace()

May need some cleaning here, given that `from` may or may not be serializable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_descback to summary
protected String _desc

Lazily-constructed description of this instance; needed mostly to allow JDK serialization to work in case where _from is non-serializable (and has to be dropped) but we still want to pass actual description along.

_fromback to summary
protected transient Object _from
_indexback to summary
protected int _index

Index within a Collection instance that contained the reference; used if index is relevant and available. If either not applicable, or not available, -1 is used to denote "not known" (or not relevant).

_propertyNameback to summary
protected String _propertyName

Name of property (for POJO) or key (for Maps) that is part of the reference. May be null for Collection types (which generally have _index defined), or when resolving Map classes without (yet) having an instance to operate on.

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

Referenceback to summary
protected Reference()

Default constructor for deserialization purposes

Referenceback to summary
public Reference(Object from)
Referenceback to summary
public Reference(Object from, String propertyName)
Referenceback to summary
public Reference(Object from, int index)

Method Detail

fromback to summary
public Object from()

Object through which reference was resolved. Can be either actual instance (usually the case for serialization), or Class (usually the case for deserialization).

Note that this the accessor is not a getter on purpose as we cannot (in general) serialize/deserialize this reference

getDescriptionback to summary
public String getDescription()
getIndexback to summary
public int getIndex()
getPropertyNameback to summary
public String getPropertyName()
setDescriptionback to summary
pack-priv void setDescription(String d)
setIndexback to summary
pack-priv void setIndex(int ix)
setPropertyNameback to summary
pack-priv void setPropertyName(String n)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
writeReplaceback to summary
pack-priv Object writeReplace()

May need some cleaning here, given that `from` may or may not be serializable.