Package com.fasterxml.jackson.databind
Class JsonMappingException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.io.IOException
-
- com.fasterxml.jackson.core.JsonProcessingException
-
- com.fasterxml.jackson.databind.JsonMappingException
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
InvalidDefinitionException
,MismatchedInputException
,UnresolvedForwardReference
,ValueInstantiationException
public class JsonMappingException extends JsonProcessingException
Checked exception used to signal fatal problems with mapping of content, distinct from low-level I/O problems (signaled using simpleIOException
s) or data encoding/decoding problems (signaled withJsonParseException
,JsonGenerationException
).One additional feature is the ability to denote relevant path of references (during serialization/deserialization) to help in troubleshooting.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JsonMappingException.Reference
Simple bean class used to contain references.
-
Constructor Summary
Constructors Constructor Description JsonMappingException(Closeable processor, String msg)
JsonMappingException(Closeable processor, String msg, JsonLocation loc)
JsonMappingException(Closeable processor, String msg, Throwable problem)
JsonMappingException(String msg)
Deprecated.Since 2.7 Use variant that takesJsonParser
insteadJsonMappingException(String msg, JsonLocation loc)
Deprecated.Since 2.7 Use variant that takesJsonParser
insteadJsonMappingException(String msg, JsonLocation loc, Throwable rootCause)
Deprecated.Since 2.7 Use variant that takesJsonParser
insteadJsonMappingException(String msg, Throwable rootCause)
Deprecated.Since 2.7 Use variant that takesJsonParser
instead
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JsonMappingException
from(JsonGenerator g, String msg)
static JsonMappingException
from(JsonGenerator g, String msg, Throwable problem)
static JsonMappingException
from(JsonParser p, String msg)
static JsonMappingException
from(JsonParser p, String msg, Throwable problem)
static JsonMappingException
from(DeserializationContext ctxt, String msg)
static JsonMappingException
from(DeserializationContext ctxt, String msg, Throwable t)
static JsonMappingException
from(SerializerProvider ctxt, String msg)
static JsonMappingException
from(SerializerProvider ctxt, String msg, Throwable problem)
static JsonMappingException
fromUnexpectedIOE(IOException src)
Factory method used when "upgrading" anIOException
intoJsonMappingException
: usually only needed to comply with a signature.String
getLocalizedMessage()
String
getMessage()
Method is overridden so that we can properly inject description of problem path, if such is defined.List<JsonMappingException.Reference>
getPath()
Method for accessing full structural path within type hierarchy down to problematic property.String
getPathReference()
Method for accessing description of path that lead to the problem that triggered this exceptionStringBuilder
getPathReference(StringBuilder sb)
Object
getProcessor()
Method that allows accessing underlying processor that triggered this exception; typically eitherJsonParser
orJsonGenerator
for exceptions that originate from streaming API.void
prependPath(JsonMappingException.Reference r)
void
prependPath(Object referrer, int index)
Method called to prepend a reference information in front of current pathvoid
prependPath(Object referrer, String fieldName)
Method called to prepend a reference information in front of current pathString
toString()
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.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.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.-
Methods inherited from class com.fasterxml.jackson.core.JsonProcessingException
clearLocation, getLocation, getOriginalMessage
-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
-
-
-
Constructor Detail
-
JsonMappingException
@Deprecated public JsonMappingException(String msg)
Deprecated.Since 2.7 Use variant that takesJsonParser
instead
-
JsonMappingException
@Deprecated public JsonMappingException(String msg, Throwable rootCause)
Deprecated.Since 2.7 Use variant that takesJsonParser
instead
-
JsonMappingException
@Deprecated public JsonMappingException(String msg, JsonLocation loc)
Deprecated.Since 2.7 Use variant that takesJsonParser
instead
-
JsonMappingException
@Deprecated public JsonMappingException(String msg, JsonLocation loc, Throwable rootCause)
Deprecated.Since 2.7 Use variant that takesJsonParser
instead
-
JsonMappingException
public JsonMappingException(Closeable processor, String msg, Throwable problem)
- Since:
- 2.7
-
JsonMappingException
public JsonMappingException(Closeable processor, String msg, JsonLocation loc)
- Since:
- 2.7
-
-
Method Detail
-
from
public static JsonMappingException from(JsonParser p, String msg)
- Since:
- 2.7
-
from
public static JsonMappingException from(JsonParser p, String msg, Throwable problem)
- Since:
- 2.7
-
from
public static JsonMappingException from(JsonGenerator g, String msg)
- Since:
- 2.7
-
from
public static JsonMappingException from(JsonGenerator g, String msg, Throwable problem)
- Since:
- 2.7
-
from
public static JsonMappingException from(DeserializationContext ctxt, String msg)
- Since:
- 2.7
-
from
public static JsonMappingException from(DeserializationContext ctxt, String msg, Throwable t)
- Since:
- 2.7
-
from
public static JsonMappingException from(SerializerProvider ctxt, String msg)
- Since:
- 2.7
-
from
public static JsonMappingException from(SerializerProvider ctxt, String msg, Throwable problem)
- Since:
- 2.7
-
fromUnexpectedIOE
public static JsonMappingException fromUnexpectedIOE(IOException src)
Factory method used when "upgrading" anIOException
intoJsonMappingException
: 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
-
wrapWithPath
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.
-
wrapWithPath
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.
-
wrapWithPath
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.
-
getPath
public List<JsonMappingException.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)
-
prependPath
public void prependPath(Object referrer, String fieldName)
Method called to prepend a reference information in front of current path
-
prependPath
public void prependPath(Object referrer, int index)
Method called to prepend a reference information in front of current path
-
prependPath
public void prependPath(JsonMappingException.Reference r)
-
getProcessor
public Object getProcessor()
Description copied from class:JsonProcessingException
Method that allows accessing underlying processor that triggered this exception; typically eitherJsonParser
orJsonGenerator
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.- Overrides:
getProcessor
in classJsonProcessingException
- Returns:
- Originating processor, if available; null if not.
-
getLocalizedMessage
public String getLocalizedMessage()
- Overrides:
getLocalizedMessage
in classThrowable
-
getMessage
public String getMessage()
Method is overridden so that we can properly inject description of problem path, if such is defined.- Overrides:
getMessage
in classJsonProcessingException
-
toString
public String toString()
- Overrides:
toString
in classJsonProcessingException
-
-