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

Re-Enable default values for text nodes #4496

Closed
henning-meinhardt opened this issue Apr 23, 2024 · 5 comments
Closed

Re-Enable default values for text nodes #4496

henning-meinhardt opened this issue Apr 23, 2024 · 5 comments
Labels
duplicate Duplicate of an existing (usually earlier) issue

Comments

@henning-meinhardt
Copy link

henning-meinhardt commented Apr 23, 2024

Is your feature request related to a problem? Please describe.

Starting with Jackson databind 2.17 the method JsonNode.asText(String defaultValue) was deprecated without giving an advice how to fill the missing functionality. In #463 you added the possibility to return a default value when querying a missing text node like so:

JsonNode someNode = ..... // for example an empty node {}
String value = someNode.path ("property").asText ("defaultValue");

When property property was not present, value was set to defaultValue. According to the deprecation comment this method should not be used any longer. But there is no advice how to implement the use case "go with a default value when the property in question is not defined" in an adequately short manner. At least I could not find any useful replacement around the JsonNode class. Is there something I missed?

Describe the solution you'd like

I would like you to rethink the deprecation or provide an easy replacement (in one statement) for getting a text property value or a fallback when missing.

I also just commented on #463 giving the workarounds I came up so far, both much too complicated compared to the existing method. There I also tried to explain why the given reason for deprecation doesn't seem valid to me.

Usage example

No response

Additional context

No response

@henning-meinhardt henning-meinhardt added the to-evaluate Issue that has been received but not yet evaluated label Apr 23, 2024
@JooHyukKim
Copy link
Member

Similar to #4471

@henning-meinhardt
Copy link
Author

@JooHyukKim exactly, thanks for pointing that out, didn't find that ticket

@JooHyukKim
Copy link
Member

I would like you to rethink the deprecation or provide an easy replacement

Kinda valid point.

Also, as per JavaDoc..

     * NOTE: deprecated since 2.17 because {@link #asText()} very rarely returns
     * {@code null} for any node types -- in fact, neither {@link MissingNode}
     * nor {@code NullNode} return {@code null} from {@link #asText()}.

... it was deprecated for the code path being dead cold, but un-deprecation requests tell otherwise. 🤔

@cowtowncoder
Copy link
Member

@henning-meinhardt Did you not actually try to search for an existing issue? The very previous open one, #4471 covers this. So let's discuss there; closing this as duplicate.

@cowtowncoder cowtowncoder closed this as not planned Won't fix, can't repro, duplicate, stale Apr 24, 2024
@cowtowncoder cowtowncoder added duplicate Duplicate of an existing (usually earlier) issue and removed to-evaluate Issue that has been received but not yet evaluated labels Apr 24, 2024
@henning-meinhardt
Copy link
Author

@cowtowncoder you are right, i should have found this, but unfortunately the issue did no exist yet when I stumbled upon the problem. Just came to report it yesterday. Sorry for inconvenience. Seems to be problem that bothers not just me ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Duplicate of an existing (usually earlier) issue
Projects
None yet
Development

No branches or pull requests

3 participants