Closed wcampbell0x2a closed 3 years ago
The 1:
in your yaml is deserialized as a number, so the deserialization fails when it tries to deserialize it into the cases: HashMap<String, String>,
, since a number is not a String
. Your example passes the tests when using a HashMap<i32, String>
. The code work without the untagged
, so this looks like another variants of serde-rs/serde#1183.
You could change the key type of the HashMap
to something which works in both cases, for example an enum with a number and a string variant. Another option to solve this is to write custom deserialization code and use the with
attribute of serde to call it.
The
1:
in your yaml is deserialized as a number, so the deserialization fails when it tries to deserialize it into thecases: HashMap<String, String>,
, since a number is not aString
. Your example passes the tests when using aHashMap<i32, String>
. The code work without theuntagged
, so this looks like another variants of serde-rs/serde#1183.
Thanks! I actually now just use the serde_yaml::Value
, which correctly parses.
You could change the key type of the
HashMap
to something which works in both cases, for example an enum with a number and a string variant. Another option to solve this is to write custom deserialization code and use thewith
attribute of serde to call it.
I actually need the HashMap, since the real stuff actually has the following:
fn test_fails() {
let s = r#"type:
switch-on: rec_type
cases:
1: rec_type_1
2: rec_type_2
"#;
Thanks for the help!
I'm a bit new to using the
serde
as well as theserde-yaml
crates, but asking for some help with a small part of the https://doc.kaitai.io/user_guide.html parsing from yaml.Example (rust playground link)
Test output
Thanks for any help, I can't figure out how to do untagged parsers for these two different states. If there is a better place to ask this question lmk. Thanks.