Open plotchy opened 1 year ago
idk why strum serialize serializes as str as escaped string
@DaniPopes mind taking a look?
FYI Adding in a line for a serde alias lets the test pass.
#[strum(serialize = "bsc")]
#[serde(alias = "bsc")]
BinanceSmartChain = 56,
Output:
running 1 test
[src/lib.rs:288] &chain_str = "\"mainnet\""
[src/lib.rs:290] &chain_deser = Mainnet
[src/lib.rs:295] &chain_str = "\"bsc\""
[src/lib.rs:297] &chain_deser = BinanceSmartChain
test tests::test_chain_deser ... ok
idk why strum serialize serializes as str as escaped string
that's just serde_json adding quotes for json and dbg! using Debug on a str escaping it
What ethers version / ref are you using? @plotchy
@DaniPopes
ethers-core v1.0.2 (https://github.com/gakonst/ethers-rs#0187bedd)
Ok that's latest commit on master, but this has been a thing forever: the problem here is that we derive Deserialize which uses snake_case while everything else uses kebab-case and strum aliases.
I'm not sure how to fix this other than adding each and every kebab-case + alias to serde too, or a custom Deserialize impl with manual matching for snake_case + fallback to String::deserialize -> FromStr... @mattsse
Revisiting this from a long time ago. Noticing your comment in https://github.com/gakonst/ethers-rs/pull/2270
Doesn't fix it because you still need to replace kebab-case to snake_case
for my needs that fix worked great. Feel free to keep this open as an issue to track that if you'd like, but just wanted to let you know im satisfied with the patch
Description Using serde_json to save serializations of Chains within files, and later deserializing the files back into Chain objects.
Ran into an issue with the Chain::BinanceSmartChain deserialization failing. Below is a test showing the issue:
Here is the output of the test:
Looks like it wants to see "binance_smart_chain" I imagine this occurs similarly for the other
#[strum(serialize = ...)]
Chains as well. link to Chain enum