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 number types [JSTEP-3] #5003

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

Comments

@cowtowncoder
Copy link
Member

cowtowncoder commented Mar 4, 2025

(note: continuation of #4958 and #4991 )

Jackson 2.x has methods like JsonNode.asInt() to allow some additional coercions from types not directly compatible (int only coercible from JSON Numbers):

  • asInt() similar to intValue() but allows coercion from (compatible) String, as well as null (and even Boolean?). But if not, throw exception
  • asIntOpt() like asInt() but returns OptionalInt, either present (as per asInt()) or absent (instead of exception)

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

Types/methods to handle:

  • asDecimal() (BigDecimal)
  • asDouble()
  • asInt()
  • asLong()

but let's also add

  • asBigInteger()

(probably not asFloat() or asShort() or asByte())

@cowtowncoder cowtowncoder added the 3.0 Issue planned for initial 3.0 release label Mar 4, 2025
@cowtowncoder cowtowncoder changed the title Extend, improve set of JsonNode.asXxx() methods Extend, improve set of JsonNode.asXxx() methods for number types Mar 19, 2025
@cowtowncoder cowtowncoder added this to the 3.0.0-rc2 milestone Mar 26, 2025
@cowtowncoder cowtowncoder changed the title Extend, improve set of JsonNode.asXxx() methods for number types Extend, improve set of JsonNode.asXxx() methods for number types [JSTEP-3] Mar 26, 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