You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like nested untagged enums can be deserialized to the wrong variant. In the repro below, this only occurs if the number of fields in StructWithStrings matches the number of entries in Foo:Arry's vector (tested for n=1..5). If a second string entry is added to the Foo::Array object or if another field is added to StructWithString, the assert doesn't trigger.
use serde::{Deserialize,Serialize};#[derive(Debug,Eq,PartialEq,Deserialize,Serialize)]pubstructStructWithStrings{pubfield1:String,}#[derive(Debug,Eq,PartialEq,Deserialize,Serialize)]#[serde(untagged)]pubenumScalarData{String(String),LanguageString(StructWithStrings),}#[derive(Debug,Eq,PartialEq,Serialize,Deserialize)]#[serde(untagged)]pubenumFoo{Scalar(ScalarData),Array(Vec<ScalarData>),}fnmain(){let val = Foo::Array(vec![ScalarData::String("String 1".to_string()),]);println!("Val: {val:#?}");let json_val = serde_json::to_string_pretty(&val).unwrap();println!("JSON: {json_val}");let val_again:Foo = serde_json::from_str(&json_val).unwrap();println!("Val again: {val_again:#?}");assert_eq!(val, val_again);}
It looks like nested untagged enums can be deserialized to the wrong variant. In the repro below, this only occurs if the number of fields in
StructWithStrings
matches the number of entries inFoo:Arry
's vector (tested for n=1..5). If a second string entry is added to theFoo::Array
object or if another field is added toStructWithString
, the assert doesn't trigger.Output
I've also put the repro in a separate repo here: https://github.com/WillLillis/serde_json_repro. I originally ran into this while working with lsp-types's
Hover
struct. Thanks so much for this amazing project!The text was updated successfully, but these errors were encountered: