-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Deprecate JsonNode.asText(String)
(note: reverted in 2.17.1)
#4416
Comments
Ok explanation makes sense: I'd vote for deprecation. We can do that for 2.17 -- would be happy to get a PR (with Javadoc explaining reasoning). |
JsonNode.asText(String)
Interestingly enough, this method behaves bit different than advertised: "defaultValue" will be returned for all All the more reason to deprecate it, tho, remove from 3.0. |
I didn't get to that one apparently. 😄 Thank you for the fix! |
@apeteri no problem; not a big deal. Thank you for pointing this out. |
Looks like this should be reverted, based on feedback and better understanding on logic & updated description. |
JsonNode.asText(String)
JsonNode.asText(String)
(note: reverted in 2.17.1)
Reverted for 2.17.1 via #4471 . |
NOTE: see #4471 for current state -- this was done for 2.17.0 release but reverted for 2.17.1
Describe the bug
It looks like the fallback value in
JsonNode#asText(String)
never gets a chance to appear as the 0-argasText()
should never returnnull
, according to its Javadoc:jackson-databind/src/main/java/tools/jackson/databind/JsonNode.java
Lines 604 to 623 in dca0c27
This seems to be the case in all implementations of
asText()
I can see, and has been corroborated in other issues such as #25.The only exception is if someone calls
TextNode(String)
directly withnull
as the input.TextNode#valueOf(String)
already converts these cases intonull
references, so the "almost" in the title is quite strong.Version Information
2.16.1
Expected behavior
Either replace the
null
check with an emptyness check (but then "legitimate empty" strings will also use the default value), or deprecate the method? Not quite sure!The text was updated successfully, but these errors were encountered: