public abstract class DeserializationProblemHandler extends Object
DeserializationConfig
object owner by
ObjectMapper
) to get called when a potentially
recoverable problem is encountered during deserialization
process. Handlers can try to resolve the problem, throw
an exception or just skip the content.
Default implementations for all methods implemented minimal "do nothing" functionality, which is roughly equivalent to not having a registered listener at all. This allows for only implemented handler methods one is interested in, without handling other cases.
NOTE: it is typically NOT acceptable to simply do nothing,
because this will result in unprocessed tokens being left in
token stream (read via JsonParser
, in case a structured
(JSON Object or JSON Array) value is being pointed to by parser.
Modifier and Type | Field and Description |
---|---|
static Object |
NOT_HANDLED
Marker value returned by some handler methods to indicate that
they could not handle problem and produce replacement value.
|
Constructor and Description |
---|
DeserializationProblemHandler() |
Modifier and Type | Method and Description |
---|---|
Object |
handleInstantiationProblem(DeserializationContext ctxt,
Class<?> instClass,
Object argument,
Throwable t)
Method called when instance creation for a type fails due to an exception.
|
Object |
handleMissingInstantiator(DeserializationContext ctxt,
Class<?> instClass,
com.fasterxml.jackson.core.JsonParser p,
String msg)
Deprecated.
Since 2.9: use variant that takes
ValueInstantiator |
Object |
handleMissingInstantiator(DeserializationContext ctxt,
Class<?> instClass,
ValueInstantiator valueInsta,
com.fasterxml.jackson.core.JsonParser p,
String msg)
Method called when instance creation for a type fails due to lack of an
instantiator.
|
JavaType |
handleMissingTypeId(DeserializationContext ctxt,
JavaType baseType,
TypeIdResolver idResolver,
String failureMsg)
Handler method called if an expected type id for a polymorphic value is
not found and no "default type" is specified or allowed.
|
Object |
handleUnexpectedToken(DeserializationContext ctxt,
Class<?> targetType,
com.fasterxml.jackson.core.JsonToken t,
com.fasterxml.jackson.core.JsonParser p,
String failureMsg)
Deprecated.
Since 2.10
|
Object |
handleUnexpectedToken(DeserializationContext ctxt,
JavaType targetType,
com.fasterxml.jackson.core.JsonToken t,
com.fasterxml.jackson.core.JsonParser p,
String failureMsg)
Method that deserializers should call if the first token of the value to
deserialize is of unexpected type (that is, type of token that deserializer
cannot handle).
|
boolean |
handleUnknownProperty(DeserializationContext ctxt,
com.fasterxml.jackson.core.JsonParser p,
JsonDeserializer<?> deserializer,
Object beanOrClass,
String propertyName)
Method called when a JSON Object property with an unrecognized
name is encountered.
|
JavaType |
handleUnknownTypeId(DeserializationContext ctxt,
JavaType baseType,
String subTypeId,
TypeIdResolver idResolver,
String failureMsg)
Handler method called if resolution of type id from given String failed
to produce a subtype; usually because logical id is not mapped to actual
implementation class.
|
Object |
handleWeirdKey(DeserializationContext ctxt,
Class<?> rawKeyType,
String keyValue,
String failureMsg)
Method called when a property name from input cannot be converted to a
non-Java-String key type (passed as
rawKeyType ) due to format problem. |
Object |
handleWeirdNativeValue(DeserializationContext ctxt,
JavaType targetType,
Object valueToConvert,
com.fasterxml.jackson.core.JsonParser p)
Method called when an embedded (native) value (
JsonToken.VALUE_EMBEDDED_OBJECT )
cannot be converted directly into expected value type (usually POJO). |
Object |
handleWeirdNumberValue(DeserializationContext ctxt,
Class<?> targetType,
Number valueToConvert,
String failureMsg)
Method called when a numeric value (integral or floating-point from input
cannot be converted to a non-numeric value type due to specific problem
(as opposed to numeric values never being usable).
|
Object |
handleWeirdStringValue(DeserializationContext ctxt,
Class<?> targetType,
String valueToConvert,
String failureMsg)
Method called when a String value
cannot be converted to a non-String value type due to specific problem
(as opposed to String values never being usable).
|
public static final Object NOT_HANDLED
public boolean handleUnknownProperty(DeserializationContext ctxt, com.fasterxml.jackson.core.JsonParser p, JsonDeserializer<?> deserializer, Object beanOrClass, String propertyName) throws IOException
parser.skipChildren();
Note: DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
)
takes effect only after handler is called, and only
if handler did not handle the problem.
beanOrClass
- Either bean instance being deserialized (if one
has been instantiated so far); or Class that indicates type that
will be instantiated (if no instantiation done yet: for example
when bean uses non-default constructors)p
- Parser to use for handling problematic contentIOException
public Object handleWeirdKey(DeserializationContext ctxt, Class<?> rawKeyType, String keyValue, String failureMsg) throws IOException
rawKeyType
) due to format problem.
Handler may choose to do one of 3 things:
NOT_HANDLED
IOException
to indicate specific fail message (instead of
standard exception caller would throw
failureMsg
- Message that will be used by caller (by calling
DeserializationContext.weirdKeyException(Class, String, String)
)
to indicate type of failure unless handler produces key to useNOT_HANDLED
to indicate that handler does not know
what to do (and exception may be thrown), or value to use as key (possibly
null
IOException
public Object handleWeirdStringValue(DeserializationContext ctxt, Class<?> targetType, String valueToConvert, String failureMsg) throws IOException
NOT_HANDLED
IOException
to indicate specific fail message (instead of
standard exception caller would throw
targetType
) to use as
replacement, and continue processing.
failureMsg
- Message that will be used by caller (by calling
DeserializationContext.weirdNumberException(java.lang.Number, java.lang.Class<?>, java.lang.String)
)
to indicate type of failure unless handler produces key to useNOT_HANDLED
to indicate that handler does not know
what to do (and exception may be thrown), or value to use as (possibly
null
)IOException
public Object handleWeirdNumberValue(DeserializationContext ctxt, Class<?> targetType, Number valueToConvert, String failureMsg) throws IOException
NOT_HANDLED
IOException
to indicate specific fail message (instead of
standard exception caller would throw
targetType
) to use as
replacement, and continue processing.
failureMsg
- Message that will be used by caller (by calling
DeserializationContext.weirdNumberException(java.lang.Number, java.lang.Class<?>, java.lang.String)
)
to indicate type of failure unless handler produces key to useNOT_HANDLED
to indicate that handler does not know
what to do (and exception may be thrown), or value to use as (possibly
null
)IOException
public Object handleWeirdNativeValue(DeserializationContext ctxt, JavaType targetType, Object valueToConvert, com.fasterxml.jackson.core.JsonParser p) throws IOException
JsonToken.VALUE_EMBEDDED_OBJECT
)
cannot be converted directly into expected value type (usually POJO).
Handler may choose to do one of 3 things:
NOT_HANDLED
IOException
to indicate specific fail message (instead of
standard exception caller would throw
targetType
) to use as
replacement, and continue processing.
NOT_HANDLED
to indicate that handler does not know
what to do (and exception may be thrown), or value to use (possibly
null
)IOException
@Deprecated public Object handleUnexpectedToken(DeserializationContext ctxt, Class<?> targetType, com.fasterxml.jackson.core.JsonToken t, com.fasterxml.jackson.core.JsonParser p, String failureMsg) throws IOException
handleUnexpectedToken(DeserializationContext, JavaType, JsonToken, JsonParser, String)
IOException
public Object handleUnexpectedToken(DeserializationContext ctxt, JavaType targetType, com.fasterxml.jackson.core.JsonToken t, com.fasterxml.jackson.core.JsonParser p, String failureMsg) throws IOException
JsonToken.START_ARRAY
instead of
JsonToken.VALUE_NUMBER_INT
or JsonToken.VALUE_NUMBER_FLOAT
.
NOT_HANDLED
IOException
to indicate specific fail message (instead of
standard exception caller would throw
targetType
) to use as replacement;
value may be `null` as well as expected target type.
failureMsg
- Message that will be used by caller
to indicate type of failure unless handler produces value to useNOT_HANDLED
to indicate that handler does not know
what to do (and exception may be thrown), or value to use (possibly
null
IOException
public Object handleInstantiationProblem(DeserializationContext ctxt, Class<?> instClass, Object argument, Throwable t) throws IOException
NOT_HANDLED
IOException
to indicate specific fail message (instead of
standard exception caller would throw
targetType
) to use as
replacement, and continue processing.
null
to use null as value but not to try further
processing (in cases where properties would otherwise be bound)
instClass
- Type that was to be instantiatedargument
- (optional) Additional argument that was passed to creator, if anyt
- Exception that caused instantiation failureNOT_HANDLED
to indicate that handler does not know
what to do (and exception may be thrown), or value to use (possibly
null
IOException
public Object handleMissingInstantiator(DeserializationContext ctxt, Class<?> instClass, ValueInstantiator valueInsta, com.fasterxml.jackson.core.JsonParser p, String msg) throws IOException
NOT_HANDLED
IOException
to indicate specific fail message (instead of
standard exception caller would throw
targetType
) to use as replacement;
value may be `null` as well as expected target type.
instClass
- Type that was to be instantiatedp
- Parser to use for accessing content that needs handling, to either
use it or skip it (latter with JsonParser.skipChildren()
.NOT_HANDLED
to indicate that handler does not know
what to do (and exception may be thrown), or value to use (possibly
null
IOException
public JavaType handleUnknownTypeId(DeserializationContext ctxt, JavaType baseType, String subTypeId, TypeIdResolver idResolver, String failureMsg) throws IOException
IOException
to indicate specific fail message (instead of
standard exception caller would throw
ctxt
- Deserialization context to use for accessing information or
constructing exception to throwbaseType
- Base type to use for resolving subtype idsubTypeId
- Subtype id that failed to resolvefailureMsg
- Informational message that would be thrown as part of
exception, if resolution still failsIOException
public JavaType handleMissingTypeId(DeserializationContext ctxt, JavaType baseType, TypeIdResolver idResolver, String failureMsg) throws IOException
IOException
to indicate specific fail message (instead of
standard exception caller would throw
ctxt
- Deserialization context to use for accessing information or
constructing exception to throwbaseType
- Base type to use for resolving subtype idfailureMsg
- Informational message that would be thrown as part of
exception, if resolution still failsIOException
@Deprecated public Object handleMissingInstantiator(DeserializationContext ctxt, Class<?> instClass, com.fasterxml.jackson.core.JsonParser p, String msg) throws IOException
ValueInstantiator
IOException
Copyright © 2008–2022 FasterXML. All rights reserved.