Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/serde_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1380,3 +1380,12 @@ impl DeJson for std::time::SystemTime {
}
}
}

impl<T> SerJson for &T
where
T: SerJson + ?Sized,
{
fn ser_json(&self, d: usize, s: &mut SerJsonState) {
(**self).ser_json(d, s);
}
}
15 changes: 15 additions & 0 deletions tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,21 @@
assert_eq!(foo.map["qwe"], 2);
}

#[cfg(feature = "std")]
#[test]
fn serialize_hashmap_with_str_keys() {
let mut hm: HashMap<&str, i32> = HashMap::new();
hm.insert("foo", 1);
hm.insert("bar", 2);

let json = SerJson::serialize_json(&hm);

let hm: HashMap<String, i32> = DeJson::deserialize_json(&json).unwrap();
assert_eq!(hm.len(), 2);
assert_eq!(hm["foo"], 1);
assert_eq!(hm["bar"], 2);
}

#[cfg(feature = "std")]
#[test]
fn serialize_hashmap_with_custom_hasher() {
Expand Down Expand Up @@ -1090,7 +1105,7 @@
pub struct Test(i32, pub i32, pub(crate) String, f32);

#[derive(DeJson, SerJson, PartialEq)]
pub struct Vec2(pub(crate) f32, pub(crate) f32);

Check warning on line 1108 in tests/json.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features NoStd (json)

struct `Vec2` is never constructed

Check warning on line 1108 in tests/json.rs

View workflow job for this annotation

GitHub Actions / Test No Std (ubuntu-latest, x86_64-unknown-linux-gnu)

struct `Vec2` is never constructed

Check warning on line 1108 in tests/json.rs

View workflow job for this annotation

GitHub Actions / Test No Std (ubuntu-latest, x86_64-unknown-linux-gnu)

struct `Vec2` is never constructed

let test = Test(0, 1, "asd".to_string(), 2.);
let bytes = SerJson::serialize_json(&test);
Expand Down
Loading