3Hren / 3Hren/msgpack-rust

Cannot deserialize the `serde_json::RawValue`

Open
#329 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
1.4k
Forks
162
PR merge metrics
No merged PRs in 30d

Description

Hello!

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 = rmp_serde::from_slice(&bytes).expect("deserialization not working");

assert_eq!(raw_value.get(), expected_value);
}
```

I tried:
1) wrap it in Newtype: `struct NewType(Box)`;
2) use `struct NewType { inner: Box}` 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 = serde_json::from_slice(&bytes).expect("deserialization not working");

assert_eq!(raw_value.get(), expected_value);
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.