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
Attempting to roundtrip a value fails for the Bug struct in the reduced example below while it works for Working, the only difference being the DefaultOnError on the field field in Bug.
I would have expected both tests to pass but only test_working does.
use serde_with::{serde_as,DefaultOnError};#[derive(Debug,Default, serde::Serialize, serde::Deserialize,Clone,PartialEq,Eq)]#[repr(u8)]pubenumEnum{#[default]A,B,}#[serde_as]#[derive(Debug,Clone, serde::Deserialize, serde::Serialize,PartialEq,Eq)]pubstructBug{#[serde_as(as = "DefaultOnError")]#[serde(default)]pubfield:Enum,}#[serde_as]#[derive(Debug,Clone, serde::Deserialize, serde::Serialize,PartialEq,Eq)]pubstructWorking{#[serde(default)]pubfield:Enum,}#[test]fntest_bug(){let val = Bug{field:Enum::B,};let data = ron::to_string(&val).unwrap();let nval = ron::from_str(&data).unwrap();assert_eq!(val, nval)}#[test]fntest_working(){let val = Working{field:Enum::B,};let data = ron::to_string(&val).unwrap();let nval = ron::from_str(&data).unwrap();assert_eq!(val, nval)}
[package]
name = "serde_with_bug"version = "0.1.0"edition = "2021"
[dependencies]
ron = "0.8.1"serde = { version = "1.0.203", features = ["derive"] }
serde_with = "3.8.1"
The text was updated successfully, but these errors were encountered:
ron doesn't support round when a Value type is involved (e.g., for buffering). ron-rs/ron#397 That is a general issue with serde serde-rs/serde#1183.
Unfortunately, internal buffering is necessary for DefaultOnError to work. You cannot recover from Deserializer errors, as the Deserializer might be in an indeterminate state. The way around that is to deserialize into a type that will not fail, and then attempt to deserialize that into the target type.
Attempting to roundtrip a value fails for the
Bug
struct in the reduced example below while it works forWorking
, the only difference being theDefaultOnError
on thefield
field inBug
.I would have expected both tests to pass but only
test_working
does.The text was updated successfully, but these errors were encountered: