-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserved value de-serialization error #59
Comments
None, sorry. It works in tests as expected. It would be helpful if you could provide an isolated minimal repro - e.g. construct a test object using |
Actually, I do have one guess - which is the most common source of all issues in Serde - are you using |
Hm it wasn't flattened. But I can't reproduce it right now, I'm not sure exactly what happened. I'll close for now and re-open if I can find some more info. Thanks meanwhile! |
Ok I ran into this error again and found the problem; I was using tsify and they're on an older version of serde-wasm-bindgen. Added a PR to fix: madonoharu/tsify#48 |
Managed to reproduce it. This seem to happen when preserved is used in a nested type, for example this works fine: #[wasm_bindgen_test]
fn simple_preserved_value() {
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Clone, Debug)]
struct A {
#[serde(with = "serde_wasm_bindgen::preserve")]
x: JsValue,
}
let case = A { x: "test".into() };
let passed_through: A = from_value(to_value(&case).unwrap()).unwrap();
assert_eq!(case, passed_through);
} But using struct #[wasm_bindgen_test]
fn nested_preserved_value() {
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Clone, Debug)]
#[serde(tag = "type")]
enum SomeEnum {
A { a: A },
}
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Clone, Debug)]
struct A {
#[serde(with = "serde_wasm_bindgen::preserve")]
x: JsValue,
}
let case = SomeEnum::A { a: A { x: "test".into() } };
let passed_through: SomeEnum = from_value(to_value(&case).unwrap()).unwrap();
assert_eq!(case, passed_through);
} causes an error like the one mentioned in the first comment:
|
This seems to be the case only for internally tagged enum representation. Works as expected for nested structs or externally/adjacently tagged enums. |
Ah yeah this is an unfortunate side effect of another ancient Serde issue: serde-rs/serde#1183 TL;DR attributes like |
Maybe we can relax our check somehow to support this particular case (even though it will still break on more complex inputs), need to think. |
Since this is closed, is there a suggested approach? Do we need to avoid flatten entirely? |
Yeah, at least I don't know of any better approach. That's what I tend to be doing (in general with Serde, not just with serde-wasm-bindgen). |
Hi,
I'm trying to use the js value preservation, but I'm getting an error. For this code:
I'm getting the following error:
Any ideas?
The text was updated successfully, but these errors were encountered: