-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
Incorrect JSON Null reading for value types #355
Comments
The proposed change makes sense to me. We took this a step further in rallyhealth/weePickle#77 by making And yet, there are upickle tests that explicitly assert the current behavior:
For context, this behavior comes from scala:
JS coerces to the same values if needed.
Regardless, this type coercion seems slightly https://www.destroyallsoftware.com/talks/wat in a language like scala. @lihaoyi, how would you like to handle? |
Could we make this easily configurable on the custom configuration with a flag? I'd be inclined to leave the default behavior unchanged, but it should be easy to do a single It might take some plumbing to get that boolean to all the relevant places, but I think the current behavior is both long lived and also-kinda-correct enough that we should make the stricter behavior opt-in |
Here's a start to mimic weepickle's all-or-nothing null handling: c301c6e. I'm stopping short of submitting a PR since:
Going to leave for someone else to pick up the torch if they want it. |
Perhaps this calls for an additional default strict uPickle Api instance implementing the above mechanism and thus granting straightforward access to the stricter behavior, i.e.: import upickle.strict._ This would follow well-known enable strict mode pattern and would be easy to document. |
Reading basic data values types from JSON
Null
values should trigger errors since values types in Scala are not nullable.Currently, reading a JSON
Null
value produces the default value for given value type which is typically some form of zero. This is also inconsistent with JSON specification which defines null as a separate data type unrelated to number.Environment
Reproduce
Result
Expected
Fix
Add the following method override to each value type
Reader
(e.g.IntReader
):Workaround
Add the equivalent implicit overrides for each value type
Reader
to your custom configuration:The text was updated successfully, but these errors were encountered: