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

Document that serde_json allows sequences to be deserialized into structs #2480

Open
tbu- opened this issue Jun 20, 2023 · 0 comments
Open
Labels

Comments

@tbu-
Copy link
Contributor

tbu- commented Jun 20, 2023

NOTE: This is basically #2438 which was closed due to being a duplicate of #1587. #1587 is about changing that behavior (which is probably impossible given serde's backward compatibility guarantees). This issue (and the closed #2438) are about documenting the existing behavior.

Last time I saw this was https://old.reddit.com/r/rust/comments/1332t9b/ji7oo8m/, but I've also seen it earlier and found it surprising both times.

Basically both {"hello": "test", "value": 42} (expected) and ["test", 42] deserialize perfectly fine into the following struct:

#[derive(Serialize, Deserialize)]
pub struct HelloParams {
    hello: String, 
    value: i32,
}

Since this is not mentioned anywhere, this can accidentally become a used API when serde is used to parse JSON (Hyrum's law).

It would be nice if this could be featured somewhere prominently in the docs. I couldn't actually find it there, even looking for it.

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

No branches or pull requests

2 participants