I'm trying to deserialize a JSON file with a pre-existing format into my own, in Rust, using serde_json.
I'd like to do this by implementing a deserializer for the class.
My problem is that the JSON file could be malformed in such a way that raw_json_result could still decode just fine, but the resulting data structure would be itself malformed. In this case, I want to return an error.
What's the mechanism for forming a valid error object here? I'm thinking I want an Err(something_valid) line -- I just don't know how to make the something_valid.
impl<'de> Deserialize<'de> for MyClass {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw_json_result = MyAliasedClassFromJson::deserialize(deserializer)?;
MyClass::from_cal_json::<D>(cal_json)
}
}