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
Allow f32
and f64
map keys
#1027
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0503111
Allow f32 and f64 keys
overdrivenpotato f74b422
Return error on non-finite float keys
overdrivenpotato 9963405
Print map float keys with `CompactFormatter`
overdrivenpotato 22a5e9b
Deserialize float keys using `deserialize_number`
overdrivenpotato 324c5b5
Fix formatting
overdrivenpotato 18e1b59
Fix builds without `std` feature
overdrivenpotato 5762701
Use `ryu` directly when formatting float keys
overdrivenpotato 7760a1a
Remove extra variable
overdrivenpotato b0dbac7
Parse `Value::Map` numeric keys using `crate::from_str`
overdrivenpotato 468a94a
Use Deserializer::* methods instead of `.parse()` for integer keys
overdrivenpotato a4e2719
Return error if numeric key starts with whitespace
overdrivenpotato File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.parse()
is not appropriate to use here for floats. That accepts a bunch of syntax that is not considered a valid float in json. For example.0
or00
. Please make sure this accepts only representations that would be valid f32/f64 outside of a map key.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this to delegate to the parent
Deserializer
viaself.de.method(...)
. This unfortunately makes the error messages a bit worse, as we now get something like:Instead of:
I noticed a similar issue here is present with integer keys, this example works on
serde_json
master
:Is it worth updating this as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good call. I filed #1034 to follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an effort to patch #1034, I've also updated integer key parsing to use
Deserializer::*
. This still exhibits the above error degredation.Would it make sense here to parse the key into an intermediate string buffer, and then deserialize the integer value using
crate::from_str
? This would result in the original error messages for unexpected string keys, but may have a performance impact.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a check for leading whitespace, otherwise it would end up accepting potentially invalid JSON syntax.
For example this is not a legal JSON document:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'll fix the error message problem too. JSON numbers must start with
0-9
or-
. If the upcoming character is not one of those, you can avoid calling the function that would produced the bad message in this situation, and directly create a useful "invalid value" error instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've patched this with a check for whitespace characters. I don't quite follow what you mean about fixing the error, the misleading text is still present, no? E.g. this example:
Previously would print
invalid type: string "abc", expected i32 at line 1 column 6
, but after this changeset it printsexpected value at line 1 column 3
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I was thinking of doing to give a more meaningful error: #1035.