Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cannot deserialize to HashMap<bool, _> #1054

@jagill

Description

@jagill

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions