From fd2b49e1907805000ad0c7488ab3c15839f7de93 Mon Sep 17 00:00:00 2001 From: phga Date: Wed, 25 Jan 2023 15:07:39 +0100 Subject: [PATCH] feat: deserialize test --- serde_json_test/src/main.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/serde_json_test/src/main.rs b/serde_json_test/src/main.rs index 2650918..d5ac30f 100644 --- a/serde_json_test/src/main.rs +++ b/serde_json_test/src/main.rs @@ -1,19 +1,19 @@ use std::collections::HashMap; -use serde::Serialize; +use serde::{Serialize, Deserialize}; use serde_with::serde_as; -#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize)] +#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize)] struct Path(pub Vec); -#[derive(Serialize)] +#[derive(Serialize, Deserialize, Debug)] struct Rel { path: Path, count: usize, } #[serde_as] -#[derive(Serialize)] +#[derive(Serialize, Deserialize)] struct Cl1 { #[serde_as(as = "Vec<(_, _)>")] cache: HashMap, String>, @@ -21,7 +21,7 @@ struct Cl1 { type RelCache = HashMap; #[serde_as] -#[derive(Serialize)] +#[derive(Serialize, Deserialize, Debug)] struct Cl2 { #[serde_as(as = "Vec<(_, _)>")] cache: RelCache, @@ -54,6 +54,8 @@ fn main() { cache }; - let json = serde_json::to_string(&cl); - dbg!(json); + let json = serde_json::to_string(&cl).unwrap(); + dbg!(&json); + let obj: Cl2 = serde_json::from_str(&json).unwrap(); + dbg!(obj); }