IssueRaiser

Internal buffering disrupts format-specific deserialization features

Was not sure if I should file this against `serde_json` or here. As far as I can tell the bug is more likely in serde itself. While implementing #1179 I noticed that non string keys are not supported for flattening. However the same behavior happens if buffering happens for internally tagged enums: Example that shows the problem: ```rust #[macro_use] extern crate serde_derive; extern crate serde; extern crate serde_json; use std::collections::HashMap; #[derive(Deserialize, Debug)] #[serde(tag = "type")] enum E { M(HashMap<u32, ()>), } fn main() { let j = r#" {"type": "M", "1": null} "#; println!("{}", serde_json::from_str::<E>(j).unwrap_err()); } ``` This currently fails with this error: ``` invalid type: string "1", expected u32 ``` However a `HashMap<u32, ()>` is otherwise entirely permissible by `serde_json`.

Posted by mitsuhiko on Mar 18, 2018, 8:12 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments

github (Other)

Internal buffering disrupts format-specific deserialization features

mitsuhikoMar 18, 2018, 8:12 PM

Was not sure if I should file this against `serde_json` or here. As far as I can tell the bug is more likely in serde itself. While implementing #1179 I noticed that non string keys are not supported for flattening. However the same behavior happens if buffering happens for internally tagged enums: Example that shows the problem: ```rust #[macro_use] extern crate serde_derive; extern crate serde; extern crate serde_json; use std::collections::HashMap; #[derive(Deserialize, Debug)] #[serde(tag = "type")] enum E { M(HashMap<u32, ()>), } fn main() { let j = r#" {"type": "M", "1": null} "#; println!("{}", serde_json::from_str::<E>(j).unwrap_err()); } ``` This currently fails with this error: ``` invalid type: string "1", expected u32 ``` However a `HashMap<u32, ()>` is otherwise entirely permissible by `serde_json`.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue