- pub fn serialize(&self) -> String {
- format!(r#"{{\n "id": "{}",\n "created_on": {}\n}}"#, self.id, self.created_on)
- }
-
- pub fn deserialize(input: &str) -> Option<Metadata> {
- let clean_input = input
- .chars()
- .filter(|c| !c.is_whitespace())
- .collect::<String>();
-
- let id = Metadata::read_field(&clean_input, "id")?;
- let created_on = Metadata::read_field(&clean_input, "createdOn")
- .or_else(|| Metadata::read_field(&clean_input, "created_on"))?;
-
- Some(Metadata {
- id,
- created_on: created_on.parse().ok()?
- })
- }
-