Skip to content

Extend, improve set of JsonNode.asXxx() methods for non-number types (Boolean, String) #5034

@cowtowncoder

Description

@cowtowncoder

(note: similar to #5003 but for non-numbers)

Jackson 2.x has methods like JsonNode.asBoolean() to allow some additional coercions from types not directly compatible (boolean only assignable from JSON Booleans):

  • asBoolean() similar to booleanValue() but allows coercion from (compatible) String, as well as null and integer numbers. But if not, throw exception
  • asBooleanOpt() like asBoolean() but returns Optional<Boolean>, either present (as per asBoolean()) or absent (instead of exception)

but as with JsonNode.xxxValue() methods like booleanValue(), no exception is thrown but quietly default value (like false for boolean) is returned. For Jackson 3.0 we have unchecked JsonNodeException so let's use that instead.
We can also clarify coercions that are allowed, as well as extend set of asXxx() methods as it makes sense.

Relevant types/methods:

  • asBoolean()
  • asString()

Do we need to add any more?

  • asBinary()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.0Issue planned for initial 3.0 release3.0-release-notesIssues relevant for 3.0 release notes.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions