Skip to content

(2.8) Add new method(s) in DeserializationProblemHandler to allow handling of format mismatch problems #1207

@cowtowncoder

Description

@cowtowncoder

(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:

  1. Handler for case of mismatched input token type (expected number, got boolean)
  2. 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...)

To support proper handling, information to pass probably needs to include some of:

  1. Contextual object: DeserializationContext, JsonParser, JsonDeserializer in use; bean/class of bean for which value is to be used
  2. BeanProperty for which value is meant? (also gives logical name for error reporting)
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions