Open bluealert opened 6 months ago
Thanks, i will investigate it
I'm not sure. According to this implementation, we can know that sonic_rs::Value
, sonic_rs::LazyValue
and sonic_rs::OwnedLazyValue
are different from serde::Value
. They can only deserialize from structure strings like { ... }
compared to https://github.com/serde-rs/json/blob/27a4ca9d7a62394fe8f0103f3d91de59f055a4c4/src/value/de.rs#L135
The following code works:
fn main() {
let json_str1 = r#"{ "field1": { "value": "value1" }, "field2": "value2" }"#;
let json_str2 = r#"{ "field_a": "valueA", "field_b": "valueB" }"#;
process_json(json_str1);
process_json(json_str2);
}
this is an expected behavior because we hacked the visitor when using Value or LazyValue
, likes serve-json::RawValue
.
Describe the bug When I have to deserialize several different json objects, I want to use enum to unify the deserialization. And I also want to use
OwnedLazyValue
, but I found that theOwnedLazyValue
does not work in enum cases.To Reproduce
I must use
deserialize_owned_lazy_value
to deserialize field1.Expected behavior
I want the
OwnedLazyValue
works as in not enum cases. I don't need to write my own deserialization function.sonic-rs version: 0.3
Environment: Ubuntu 22.04, Rust 1.77