diff options
author | Tatu Saloranta <tatu.saloranta@iki.fi> | 2016-05-10 20:03:26 -0700 |
---|---|---|
committer | Tatu Saloranta <tatu.saloranta@iki.fi> | 2016-05-10 20:03:26 -0700 |
commit | 33ba4ad08ee2220b62028101b026e29ed4167d52 (patch) | |
tree | e31fca58ab927fd3b77a0d2b2b0e8248701a2423 /src/main/java/com/fasterxml/jackson/databind/deser/DeserializationProblemHandler.java | |
parent | bd3c3121f1ecdc07f936fff99bbaa9dac42546dd (diff) | |
download | jackson-databind-33ba4ad08ee2220b62028101b026e29ed4167d52.tar.gz |
Added DeserializationContext.handleUnknownTypeId()
Diffstat (limited to 'src/main/java/com/fasterxml/jackson/databind/deser/DeserializationProblemHandler.java')
-rw-r--r-- | src/main/java/com/fasterxml/jackson/databind/deser/DeserializationProblemHandler.java | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/DeserializationProblemHandler.java b/src/main/java/com/fasterxml/jackson/databind/deser/DeserializationProblemHandler.java index 453a16758..22a2d1775 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/DeserializationProblemHandler.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/DeserializationProblemHandler.java @@ -5,6 +5,7 @@ import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationConfig; import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.ObjectMapper; @@ -73,8 +74,8 @@ public abstract class DeserializationProblemHandler /** * Method called when a property name from input can not be converted to a - * non-Java-String key type (passed as <code>rawKeyType</code>) due to format - * problem. Handler may choose to do one of 3 things: + * non-Java-String key type (passed as <code>rawKeyType</code>) due to format problem. + * Handler may choose to do one of 3 things: *<ul> * <li>Indicate it does not know what to do by returning {@link #NOT_HANDLED} * </li> @@ -85,8 +86,6 @@ public abstract class DeserializationProblemHandler * </li> * </ul> * - * @since 2.8 - * * @param failureMsg Message that will be used by caller (by calling * {@link DeserializationContext#weirdKeyException(Class, String, String)}) * to indicate type of failure unless handler produces key to use @@ -94,6 +93,8 @@ public abstract class DeserializationProblemHandler * @return Either {@link #NOT_HANDLED} to indicate that handler does not know * what to do (and exception may be thrown), or value to use as key (possibly * <code>null</code> + * + * @since 2.8 */ public Object handleWeirdKey(DeserializationContext ctxt, Class<?> rawKeyType, String keyValue, @@ -102,4 +103,42 @@ public abstract class DeserializationProblemHandler { return NOT_HANDLED; } + + /** + * 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. + * Handler may choose to do one of following things: + *<ul> + * <li>Indicate it does not know what to do by returning `null` + * </li> + * <li>Indicate that nothing should be deserialized, by return `Void.class` + * </li> + * <li>Throw a {@link IOException} to indicate specific fail message (instead of + * standard exception caller would throw + * </li> + * <li>Return actual resolved type to use for type id. + * </li> + * </ul> + * + * @param ctxt Deserialization context to use for accessing information or + * constructing exception to throw + * @param baseType Base type to use for resolving subtype id + * @param subTypeId Subtype id that failed to resolve + * @param failureMsg Informational message that would be thrown as part of + * exception, if resolution still fails + * + * @return Actual type to use, if resolved; `null` if handler does not know what + * to do; or `Void.class` to indicate that nothing should be deserialized for + * type with the id (which caller may choose to do... or not) + * + * @since 2.8 + */ + public JavaType handleUnknownTypeId(DeserializationContext ctxt, + JavaType baseType, String subTypeId, + String failureMsg) + throws IOException + { + return null; + } } |