-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Proposal: Add Nullable Conversion Methods (e.g., asNullableInt) for JsonNode #4802
Comments
There's no such method yet? Then makes sense wrt usage. But I'm a bit concerned about the naming though. 'int' can never be nullable in Java, only Kotlin. 'Integer' can be nullable in Java. We might want to check Scala as well. |
java.lang.Integer is the best return type - works for Java, Kotlin and Scala. I think the changes could end up being very large because we would probably need a canConvertToNullableInt method too (as well as for other number types and boolean). canConvertToNullableInt would return true if the underlying number data was a valid int but also true if the data is null. |
Now that you mention it PJ, if we were to implement, is it possible that we might end up being quite large, for Float or Double and such🤔? The rationale behind it could be "why just only integer? Why not double or float?" |
@JooHyukKim |
Yup, I read that. Thank you 🙏🏼. The feature itself seems reasonable. |
I guess I was trying to reach this point of view. I agree that we most probably would want to have all wrapper types implementations be provided, in same version. Which immedately leads to the question of which version? Because like @pjfanning said above this could become quite large, eating up a whole new minor version. Having said that, honestly, we could consider this set of feature here as a way to attract users to adopt Jackson 3.0 more if we choose 3.0. Let's hear what @cowtowncoder has in mind wrt version & milestones, and also timing. |
Ok, first things first; there are/were some plans to further extend methods: https://github.com/FasterXML/jackson-future-ideas/wiki/JSTEP-3 now on "nullable"... that's one possibility, although use of Naming-wise for But also keep in mind there's So we need to be clear on exact expected semantics and naming. I guess what I am saying is that:
It might help if @JinseongHwang could extend a little bit on kind of actual usage. |
Thank you for your feedback 👍 |
Is your feature request related to a problem? Please describe.
Hi there,
It doesn't seem to provide the ability to convert a
JsonNode
to a nullable int(Integer
).In JsonNode.java,
asInt()
returns anint
type and if there is no value, it returns 0 as the default value.Describe the solution you'd like
I think it would be nice to have a method like
asNullableInt()
that returns anInteger
that is a nullable wrapper class.The same goes for
Long
,Double
, andBoolean
.If you agree with me, I'd like to contribute to this project.
Usage example
I'm using it like this.
(However, this is just an example, and it would be possible to pass the nullable option as a parameter.)
Additional context
No response
The text was updated successfully, but these errors were encountered: