Support for serde_json::RawValue
serde_json provides a RawValue type (with the raw_value feature flag) that just stores the raw json bytes so you can pass around a json string without having to parse it.
When simply serializing a RawValue using simd_json, it outputs an unexpected result:
{"data":{"$serde_json::private::RawValue":"{\"my_int\": 3, \"my_string\": \"hello!\"}"}}
Code to reproduce:
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["raw_value"] }
simd-json = "0.3"
use serde::{Serialize, Deserialize};
use serde_json::value::RawValue;
#[derive(Serialize, Deserialize)]
struct MyStruct {
data: Box<RawValue>,
}
fn main() {
let json = r#"{ "data": {"my_int": 3, "my_string": "hello!"}}"#;
let parsed: MyStruct = serde_json::from_str(json).unwrap();
let serialized = simd_json::to_string(&parsed).unwrap();
println!("{}", serialized);
}
And when deserializing to a RawValue, simd-json produces an error:
Error { index: 0, character: '�', error: Serde("invalid type: newtype struct, expected any valid JSON value") }
Code to reproduce:
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["raw_value"] }
simd-json = "0.3"
use serde::{Serialize, Deserialize};
use serde_json::value::RawValue;
#[derive(Serialize, Deserialize)]
struct MyStruct {
data: Box<RawValue>,
}
fn main() {
let mut json = r#"{ "data": {"my_int": 3, "my_string": "hello!"}}"#.to_owned();
let parsed: MyStruct = simd_json::from_str(&mut json).unwrap();
let serialized = simd_json::to_string(&parsed).unwrap();
println!("{}", serialized);
}
It'd be nice if simd-json support RawValue
I don't think that will be possible, raw value support like that would require the parser to not escape strings when being parsed which requires knowledge about the target value prior to parsing that code.
That said I'm open to ideas how that could be implemented without causing problems or slowdown?