-
-
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
TreeTraversingParser
does not check int bounds
#2189
Comments
Thank you for reporting this: it is valuable, and I did not think it is condescending at all. Starting with overflow: yes, I think bounds checks should work similarly and throw exception. Coercions: similarly, should be similar (or ideally identical). And in general I think Rules for coercions get trickier, and I wish there was a good overall answer. But I'll try to offer some perspective on likely reasons I implemented things that way. First, coercion from integral values to booleans were allowed for interoperability (back in the day Perl did not have Coercions across integral/floating-point is something where different users have different preferences. I think int-to-float is less controversial (and less problematic too). Now... String-to-number. That is also bit controversial, in general; and in particular difference from floating-point-as-String to Ok. Having said that, I would be interested in solid improvements, one piece/aspect at a time. And then there is work for 3.0 ( This is why dividing improvements into separate issues may help. I think this issue works, then, for |
One more thing: reference to |
Thanks for your reply. I understand how projects like these grow over time, and since you're supporting a public API, I certainly get that you want to keep compatibility-breaking changes at a minimum. I'm happy to hear I'm not totally misunderstanding the library use, but in a way, a bit sad that I won't have a super quick/simple fix to my specific problem. For now, I'll recommend my team use stricter schemas and convert
Makes sense to me; use this issue for tracking bounds checks (presumably for 2.10.0) and track other changes elsewhere. Is it reasonable for the various implementations to use a common base? I'm not super familiar with the code, so I hope i'm not too confused. I'm guessing the split is between streaming vs non-streaming encoders/decoders? I'd expect it to be possible to put both in a common underlying representation and perform coercions/bounds checks there. What might be nice is modular checks/coercions that can be swapped out for more or less strict checking, as desired, but this might be less reasonable from an efficiency standpoint, which is what I assume is the basis for the split in the first place. What do you think is the best way forward for 3.0? What kind of help do you need to get there? |
Quick note: I am actually working on this now, to add tests first for |
TreeTraversingParser
does not check int bounds
Ok: so, I did add bounds-checks for Other questions wrt coercions are valid, and it might be good file a new issue. I plan on tackling some aspects regardless, but I think my main concern has to do with configurability aspects, followed by documentation. Implementation should not be as difficult once configurability for specific desired/undesired coercions is defined. |
Similar to #1729, TreeTraversingParser does not perform bounds checks on some JSON values bound to ints.
Using Jackson version 2.9.7, here are several comparisons generated with the following code:
Without digging further into the code, it appears if the JSON value is numeric,
TreeTraversingParser
silently overflows. Maybe this is expected behavior, but to me the inconsistency between reading from a non-tree (reader/string/file, etc) versus directly from a tree seems like a bug. At the very least, it makes it less convenient to do manipulations on a JSON document before binding.I would expect an exception thrown for the all but the first three examples above, but I do understand there are use-cases for coercing values. Even so, I would expect the coercion logic to be
I'm also curious about the expected behavior when converting non-integral values. Why is
true
MismatchedInput
, but0.1
is converted? Similarly, why are0.1
,1e4
, and1e-1
acceptable, but not when in quotes, even though"10"
and other quote integers are acceptable?Thanks for all your hard work on this. I hope this issue doesn't come off as condescending. For our specific use case, we read the value as a tree, validating it against a schema, then using Jackson to bind the tree to an object. While it's true that we can specify type, minimum, and maximum values in the schema, it is prone to mistakes, and there's not necessarily a reason to tie the schema to the language implementation, provided things like overflow consistently result in an exception. Thus, I'm trying to better understand the expectations and limits Jackson has when using the tree parser.
The text was updated successfully, but these errors were encountered: