ron-rs/ron

Serialize -> Deserialize of struct crate a SpannedError

Closed this issue · 2 comments

An simple Serializing and BackDeserialize does creat an error.
Did I do something wrong?

#[derive(Clone, Debug, Decode, Default, Deserialize, Encode, PartialEq, Serialize)]
#[serde(deny_unknown_fields)] 
pub struct AvailableCards {
	pub left: u8,
	pub right: u8
}

#[derive(Clone, Debug, Deserialize, Serialize)]
struct MapProperties{
	#[serde(flatten)]
	cards: AvailableCards,
}


let map_properties = MapProperties{cards: AvailableCards{
	..Default::default()
}};
let map_properties = ron::to_string(&map_properties).unwrap();
println!("{map_properties}");
let map_properties: MapProperties = ron::from_str(&map_properties).unwrap();  //line 145
{"left":0,"right":0}
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SpannedError { code: ExpectedIdentifier, position: Position { line: 1, col: 2 } }', /home/lukas/git/m3/map/src/lib.rs:145:76
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Some with serde_json works:

let map_properties = MapProperties{cards: AvailableCards{
	..Default::default()
}};
let map_properties = serde_json::to_string(&map_properties).unwrap();
println!("{map_properties}");
let map_properties: MapProperties = serde_json::from_str(&map_properties).unwrap();
juntyr commented

Thank you for the report! This was fixed in #455, which is so far only available on the master branch. Until a new version of RON is published, can you switch your dependency to point to that? I've also added your failure case as a test case to ensure that it doesn't break in the future.

juntyr commented

Thank you @LuckyTurtleDev for the test case - it was added to the test suite in #457