Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cowtowncoder opened this issue Mar 19, 2025 · 0 comments
Labels
3.0 Issue planned for initial 3.0 release
Milestone

Comments

@cowtowncoder
Copy link
Member

cowtowncoder commented Mar 19, 2025

(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()?
@cowtowncoder cowtowncoder added the 3.0 Issue planned for initial 3.0 release label Mar 19, 2025
@cowtowncoder cowtowncoder changed the title Extend, improve set of JsonNode.asXxx() methods for non-number types Extend, improve set of JsonNode.asXxx() methods for non-number types (Boolean, String) Mar 21, 2025
@cowtowncoder cowtowncoder added this to the 3.0.0-rc2 milestone Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0 Issue planned for initial 3.0 release
Projects
None yet
Development

No branches or pull requests

1 participant