You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code fails with deserialization not working: Syntax("invalid type: newtype struct, expected any valid JSON value") on the rmp_serde:1.1.1
#[test]
fn test() {
let expected_value = r#"{"asd": "asd"}"#;
let raw_value = serde_json::value::RawValue::from_string(expected_value.into()).unwrap();
let bytes = rmp_serde::to_vec(&raw_value).unwrap();
let raw_value: Box<RawValue> = rmp_serde::from_slice(&bytes).expect("deserialization not working");
assert_eq!(raw_value.get(), expected_value);
}
I tried:
wrap it in Newtype: struct NewType(Box<RawValue>);
use struct NewType { inner: Box<RawValue>} with #[serde(flatten)] or #[serde(transparent)].
Nothing seems to work.
If I use serde_json::to_ver/from_slice, the test passes correctly.
#[test]
fn test() {
let expected_value = r#"{"asd": "asd"}"#;
let raw_value = serde_json::value::RawValue::from_string(r#"{"asd": "asd"}"#.into()).unwrap();
let bytes = serde_json::to_vec(&raw_value).unwrap();
let raw_value: Box<RawValue> = serde_json::from_slice(&bytes).expect("deserialization not working");
assert_eq!(raw_value.get(), expected_value);
}
The text was updated successfully, but these errors were encountered:
serde_json::RawValue has a hack inside it to be serialized/deserialized with serde_json, and cannot be used with other implementation (even with alternative JSON implementations).
Hello!
The following code fails with
deserialization not working: Syntax("invalid type: newtype struct, expected any valid JSON value")
on thermp_serde:1.1.1
I tried:
struct NewType(Box<RawValue>)
;struct NewType { inner: Box<RawValue>}
with#[serde(flatten)]
or#[serde(transparent)]
.Nothing seems to work.
If I use
serde_json::to_ver/from_slice
, the test passes correctly.The text was updated successfully, but these errors were encountered: