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

Cannot deserialize to HashMap<bool, _> #1054

Closed
jagill opened this issue Aug 15, 2023 · 0 comments · Fixed by #1055
Closed

Cannot deserialize to HashMap<bool, _> #1054

jagill opened this issue Aug 15, 2023 · 0 comments · Fixed by #1055

Comments

@jagill
Copy link

jagill commented Aug 15, 2023

JSON objects can only have string keys, although HashMaps can have many types of keys. In the case of i32 keys (eg HashMap<i32, i32>), serde_json coerces the stringified integer key (eg "1") into 1i32. However, that fails in the case of bool keys; it raises an error when trying to coerce "true" or "false" into true or false:

Error("invalid type: string \"false\", expected a boolean", line: 0, column: 0)

I'm assuming the coercion behavior in the bool case should be similar to the i32 case.

Playground reproduction is here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=92d5a43496299513df591ec5a6f2832c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant