-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
(note: based on ideas from #1196)
Existing DeserializationProblemHandler
only has one callback method, for handling common case of "unknown property" problem. But there are other types of failures that would probably be possible to route through such handler. One broad class of problems has to do with mismatching values, like getting a JSON String where number is expected, or getting a String with format that is not recognized as valid (such as can occur for Date/Time values).
To allow dealing with such problems, it seems reasonable to add following handlers:
- Handler for case of mismatched input token type (expected number, got boolean)
- Handler for case of invalid format (usually
String
, but not limited)
Note that there may be some corner cases here (f.ex., choice between (1) and (2) may not be clear for secondary/coerced values), but this should cover a few cases.
Compared to the earlier handler there are similarities and differences:
- In both cases, callback is given a
JsonParser
, and is responsible for using up or skipping any content for structured values (array, object) - For new methods, return type should be value to use as deserialized value, including possible
null
-- but since there is no way to indicate "not handled", callback MUST throw exception to halt processing- alternatively we could consider possibility of return a Marker object, to indicate "did not process, use standard failure"? While bit hacky, this might be the best way (actually, this could also be one of few cases where I would use
Optional
...)
- alternatively we could consider possibility of return a Marker object, to indicate "did not process, use standard failure"? While bit hacky, this might be the best way (actually, this could also be one of few cases where I would use
To support proper handling, information to pass probably needs to include some of:
- Contextual object:
DeserializationContext
,JsonParser
,JsonDeserializer
in use; bean/class of bean for which value is to be used BeanProperty
for which value is meant? (also gives logical name for error reporting)- Fail message that would be used for
Exception
to throw?
Anyway. Details method, arguments to pass etc get complicated and probably need to be refined as part of implementation.