diff --git a/src/raw.rs b/src/raw.rs index b853314c8..f171535d7 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -282,7 +282,7 @@ impl From> for Box { #[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))] pub fn to_raw_value(value: &T) -> Result, Error> where - T: Serialize, + T: Serialize + ?Sized, { let json_string = crate::to_string(value)?; Ok(RawValue::from_owned(json_string.into_boxed_str())) diff --git a/tests/test.rs b/tests/test.rs index 7dbc21638..4d195fb24 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2264,6 +2264,15 @@ fn test_raw_invalid_utf8() { ); } +#[cfg(feature = "raw_value")] +#[test] +fn test_serialize_unsized_value_to_raw_value() { + assert_eq!( + serde_json::value::to_raw_value("foobar").unwrap().get(), + r#""foobar""# + ); +} + #[test] fn test_borrow_in_map_key() { #[derive(Deserialize, Debug)]