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
When renaming a Struct via Serde, I would expect that this name would also be used in error messages.
I am unsure if this is serde or serde_json behaviour, as I was not able to find the cursory code in either repository, but please feel free to move or tell me to go somewhere else.
See this reproduction case for what happens vs what I expect to happen:
use serde::{Deserialize,Serialize};use serde_json::json;#[test]fnrepro_case(){#[derive(Deserialize,Debug)]structFoo{bar:Bar,}#[derive(Deserialize,Debug)]#[serde(rename = "AnotherName!")]structBar{qux:String,}let res = serde_json::from_value::<Foo>(json!({"bar": "not_a_struct"})).unwrap_err();// Passesassert_eq!(
res.to_string(),
"invalid type: string \"not_a_struct\", expected struct Bar");// Does not pass, but shouldassert_eq!(
res.to_string(),
"invalid type: string \"not_a_struct\", expected struct AnotherName!");}
The text was updated successfully, but these errors were encountered:
This could be expected behavior. At least in one place there is a clear indication, that this was intended -- the rust_name is explicitly distinguished from the type_name:
I think let's keep this behavior. In cases where just a type name isn't meaningful enough, one can use something like serde(expecting = "a map of proxy configs") to fill in the user-facing message.
invalid type: string "not_a_struct", expected a map of proxy configs
When renaming a Struct via Serde, I would expect that this name would also be used in error messages.
I am unsure if this is
serde
orserde_json
behaviour, as I was not able to find the cursory code in either repository, but please feel free to move or tell me to go somewhere else.See this reproduction case for what happens vs what I expect to happen:
The text was updated successfully, but these errors were encountered: