Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.databind

public Class JsonMappingException

extends DatabindException
Class Inheritance
Known Direct Subclasses
com.fasterxml.jackson.databind.deser.UnresolvedForwardReference, com.fasterxml.jackson.databind.exc.InvalidDefinitionException, com.fasterxml.jackson.databind.exc.MismatchedInputException, com.fasterxml.jackson.databind.exc.ValueInstantiationException
Imports
java.io.Closeable, .IOException, .Serializable, java.util.*, com.fasterxml.jackson.annotation.JsonIgnore, com.fasterxml.jackson.core.*, com.fasterxml.jackson.databind.util.ClassUtil

Checked exception used to signal fatal problems with mapping of content, distinct from low-level I/O problems (signaled using simple java.io.IOExceptions) or data encoding/decoding problems (signaled with com.fasterxml.jackson.core.exc.StreamReadException, com.fasterxml.jackson.core.exc.StreamWriteException).

One additional feature is the ability to denote relevant path of references (during serialization/deserialization) to help in troubleshooting.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
JsonMappingException.Reference

Simple bean class used to contain references.

Field Summary

Modifier and TypeField and Description
protected LinkedList<JsonMappingException.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.

pack-priv 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
public
JsonMappingException(String msg)
Deprecated Since 2.7 Use variant that takes JsonParser instead

public
JsonMappingException(String msg, Throwable rootCause)
Deprecated Since 2.7 Use variant that takes JsonParser instead

public
JsonMappingException(String msg, JsonLocation loc)
Deprecated Since 2.7 Use variant that takes JsonParser instead

public
JsonMappingException(String msg, JsonLocation loc, Throwable rootCause)
Deprecated Since 2.7 Use variant that takes JsonParser instead

public
public
public

Method Summary

Modifier and TypeMethod and Description
protected void
protected StringBuilder
_appendReferenceChain(StringBuilder sb)

Method that is called to add reference chain information to message, but may be overridden to customize handling, including appending other information or removing the reference chain altogether.

protected String
private static JsonGenerator
private static JsonParser
public static JsonMappingException
public static JsonMappingException
from(JsonParser p, String msg, Throwable problem)

public static JsonMappingException
public static JsonMappingException
public static JsonMappingException
public static JsonMappingException
public static JsonMappingException
public static JsonMappingException
public static JsonMappingException
fromUnexpectedIOE(IOException src)

Factory method used when "upgrading" an IOException into JsonMappingException: usually only needed to comply with a signature.

public String
getLocalizedMessage()

Overrides java.lang.Throwable.getLocalizedMessage.

Creates a localized description of this throwable.

public String
getMessage()

Overrides com.fasterxml.jackson.core.JsonProcessingException.getMessage.

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

public List<JsonMappingException.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
public Object
getProcessor()

Overrides com.fasterxml.jackson.core.JsonProcessingException.getProcessor.

Method that allows accessing underlying processor that triggered this exception; typically either JsonParser or JsonGenerator for exceptions that originate from streaming API.

public void
prependPath(Object referrer, String fieldName)

Implements abstract com.fasterxml.jackson.databind.DatabindException.prependPath.

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

public void
prependPath(Object referrer, int index)

Implements abstract com.fasterxml.jackson.databind.DatabindException.prependPath.

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

public void
public String
toString()

Overrides com.fasterxml.jackson.core.JsonProcessingException.toString.

Returns a short description of this throwable.

public JsonMappingException
public static JsonMappingException
wrapWithPath(Throwable src, Object refFrom, String refFieldName)

Method that can be called to either create a new JsonMappingException (if underlying exception is not a JsonMappingException), or augment given exception with given path/reference information.

public static JsonMappingException
wrapWithPath(Throwable src, Object refFrom, int index)

Method that can be called to either create a new JsonMappingException (if underlying exception is not a JsonMappingException), or augment given exception with given path/reference information.

public static JsonMappingException
wrapWithPath(Throwable src, JsonMappingException.Reference ref)

Method that can be called to either create a new JsonMappingException (if underlying exception is not a JsonMappingException), or augment given exception with given path/reference information.

Field Detail

_pathback to summary
protected LinkedList<JsonMappingException.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

Since
2.7
MAX_REFS_TO_LISTback to summary
pack-priv static final int MAX_REFS_TO_LIST

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

serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.fasterxml.jackson.databind.DatabindException.serialVersionUID.

Constructor Detail

JsonMappingExceptionback to summary
public JsonMappingException(String msg)

Deprecated

Since 2.7 Use variant that takes JsonParser instead

Annotations
@Deprecated
JsonMappingExceptionback to summary
public JsonMappingException(String msg, Throwable rootCause)

Deprecated

Since 2.7 Use variant that takes JsonParser instead

Annotations
@Deprecated
JsonMappingExceptionback to summary
public JsonMappingException(String msg, JsonLocation loc)

Deprecated

Since 2.7 Use variant that takes JsonParser instead

Annotations
@Deprecated
JsonMappingExceptionback to summary
public JsonMappingException(String msg, JsonLocation loc, Throwable rootCause)

Deprecated

Since 2.7 Use variant that takes JsonParser instead

Annotations
@Deprecated
JsonMappingExceptionback to summary
public JsonMappingException(Closeable processor, String msg)
Since
2.7
JsonMappingExceptionback to summary
public JsonMappingException(Closeable processor, String msg, Throwable problem)
Since
2.7
JsonMappingExceptionback to summary
public JsonMappingException(Closeable processor, String msg, JsonLocation loc)
Since
2.7

Method Detail

_appendPathDescback to summary
protected void _appendPathDesc(StringBuilder sb)
_appendReferenceChainback to summary
protected StringBuilder _appendReferenceChain(StringBuilder sb)

Method that is called to add reference chain information to message, but may be overridden to customize handling, including appending other information or removing the reference chain altogether.

Since
2.18.2
_buildMessageback to summary
protected String _buildMessage()
_generatorback to summary
private static JsonGenerator _generator(SerializerProvider ctxt)
_parserback to summary
private static JsonParser _parser(DeserializationContext ctxt)
fromback to summary
public static JsonMappingException from(JsonParser p, String msg)
Since
2.7
fromback to summary
public static JsonMappingException from(JsonParser p, String msg, Throwable problem)
Since
2.7
fromback to summary
public static JsonMappingException from(JsonGenerator g, String msg)
Since
2.7
fromback to summary
public static JsonMappingException from(JsonGenerator g, String msg, Throwable problem)
Since
2.7
fromback to summary
public static JsonMappingException from(DeserializationContext ctxt, String msg)
Since
2.7
fromback to summary
public static JsonMappingException from(DeserializationContext ctxt, String msg, Throwable t)
Since
2.7
fromback to summary
public static JsonMappingException from(SerializerProvider ctxt, String msg)
Since
2.7
fromback to summary
public static JsonMappingException from(SerializerProvider ctxt, String msg, Throwable problem)
Since
2.7
fromUnexpectedIOEback to summary
public static JsonMappingException fromUnexpectedIOE(IOException src)

Factory method used when "upgrading" an IOException into JsonMappingException: usually only needed to comply with a signature.

Note

since 2.9 should usually NOT be used on input-side (deserialization) exceptions; instead use method(s) of InputMismatchException

Since
2.1
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().

Returns:String

The localized description of this throwable.

Annotations
@Override
getMessageback to summary
public String getMessage()

Overrides com.fasterxml.jackson.core.JsonProcessingException.getMessage.

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

Returns:String

Doc from com.fasterxml.jackson.core.JsonProcessingException.getMessage.

Original message preceded by optional prefix and followed by location information, message and location information separated by a linefeed

Annotations
@Override
getPathback to summary
public List<JsonMappingException.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)
getProcessorback to summary
public Object getProcessor()

Overrides com.fasterxml.jackson.core.JsonProcessingException.getProcessor.

Doc from com.fasterxml.jackson.core.JsonProcessingException.getProcessor.

Method that allows accessing underlying processor that triggered this exception; typically either JsonParser or JsonGenerator for exceptions that originate from streaming API. Note that it is possible that `null` may be returned if code throwing exception either has no access to 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.

Returns:Object

Originating processor, if available; null if not.

Annotations
@Override
@JsonIgnore
prependPathback to summary
public void prependPath(Object referrer, String fieldName)

Implements abstract com.fasterxml.jackson.databind.DatabindException.prependPath.

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

Annotations
@Override
prependPathback to summary
public void prependPath(Object referrer, int index)

Implements abstract com.fasterxml.jackson.databind.DatabindException.prependPath.

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

Annotations
@Override
prependPathback to summary
public void prependPath(JsonMappingException.Reference r)
toStringback to summary
public String toString()

Overrides com.fasterxml.jackson.core.JsonProcessingException.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.
Returns:String

a string representation of this throwable.

Annotations
@Override
withCauseback to summary
public JsonMappingException withCause(Throwable cause)
Since
2.13
wrapWithPathback to summary
public static JsonMappingException wrapWithPath(Throwable src, Object refFrom, String refFieldName)

Method that can be called to either create a new JsonMappingException (if underlying exception is not a JsonMappingException), 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 JsonMappingException wrapWithPath(Throwable src, Object refFrom, int index)

Method that can be called to either create a new JsonMappingException (if underlying exception is not a JsonMappingException), 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 JsonMappingException wrapWithPath(Throwable src, JsonMappingException.Reference ref)

Method that can be called to either create a new JsonMappingException (if underlying exception is not a JsonMappingException), or augment given exception with given path/reference information.

Annotations
@SuppressWarnings:resource
com.fasterxml.jackson.databind back to summary

public Class JsonMappingException.Reference

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • com.fasterxml.jackson.databind.JsonMappingException.Reference
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.

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 String
_fieldName

Name of field (for beans) or key (for Maps) that is part of the reference.

protected transient Object
protected int
_index

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

private static final long

Constructor Summary

AccessConstructor and Description
protected
Reference()

Default constructor for deserialization/sub-classing purposes

public
public
Reference(Object from, String fieldName)

public
Reference(Object from, int index)

Method Summary

Modifier and TypeMethod and Description
public String
public String
public Object
getFrom()

Object through which reference was resolved.

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

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.

Since
2.8
_fieldNameback to summary
protected String _fieldName

Name of field (for beans) 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.

_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).

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

Referenceback to summary
protected Reference()

Default constructor for deserialization/sub-classing purposes

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

Method Detail

getDescriptionback to summary
public String getDescription()
getFieldNameback to summary
public String getFieldName()
getFromback to summary
public Object getFrom()

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 value must be `transient` to allow serializability (as often such Object is NOT serializable; or, in case of `Class`, may not available at the point of deserialization). As such will return `null` if instance has been passed using JDK serialization.

Annotations
@JsonIgnore
getIndexback to summary
public int getIndex()
setDescriptionback to summary
pack-priv void setDescription(String d)
setFieldNameback to summary
pack-priv void setFieldName(String n)
setIndexback to summary
pack-priv void setIndex(int ix)
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.

Returns:String

a string representation of the object

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

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