Replies: 1 comment 1 reply
-
Having the ability to deserialize would be great. I would be very happy to take a look at a PR implementing these changes. I am currently very busy with work, so please excuse me if I won't have the time to review the changes in the upcoming days. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've just started trying out Charming and it seems it'd be a good fit for my project. One thing though is I'm looking to serialize and deserialize charts, but the Chart struct doesn't implement the
Deserialize
trait, onlySerialize
. I'm doing some calculations in a web worker, which I pass back to an iframe over a MessagePort. I built the Chart object in the worker, serialized it with serde-wasm-bindgen, posted it to the iframe, and then ran into the problem that I couldn't deserialize it with serde-wasm-bindgen.I considered three options:
Work with the serialized Chart JsValue (serde-wasm-bindgen), bypassing Charming and sending the object directly to Echarts. I did experiment a bit with making Charming's Echarts::set_option function public to allow me to send the JsValue directly and this worked, but that's a rather hacky approach.
Send my raw data from the web worker to the iframe, and build the Chart object there. At least this wouldn't require any changes to Charming or hacks, but it's a bit convoluted with regard to my application. I'd have to replicate several structures that already exist in Charming to capture the configuration of the chart.
Add the Deserialize trait to Chart / throughout Charming. I tried this and it seems to work, but I haven't made any complex charts yet. I did create a couple simple tests though in tests/deserialize.rs
Here's my branch with all the changes:
https://github.com/jasoncg/charming/tree/deserialize-chart
For the most part it was just adding Deserialize, but some structures required custom deserializers.
Data structures where I had to implement a custom Deserialize trait include:
The other issue I ran in to was some vectors have
skip_serializing_if = "Vec::is_empty"
, which was causing problem with deserialization. So for all of those I set#[serde(default)]
so that they can deserialize with empty vectors.Is there another mechanism for deserializing that I'm missing? Should I submit a PR to merge these changes?
Beta Was this translation helpful? Give feedback.
All reactions