CosmWasm / serde-json-wasm

serde_json for Wasm programs (small, deterministic, no floats)
Apache License 2.0
30 stars 15 forks source link

Serialization of flatten type not supported #20

Closed whalelephant closed 1 year ago

whalelephant commented 4 years ago

Reference to: https://github.com/CosmWasm/cosmwasm-plus/issues/57

The #[serde(flatten)] serializes with serialize_struct_as_map, however, this lib does not fully implement the SerializeMap function.

This issue can be replicated when one uses cosmwasm_std::to_vec() on a struct with the flatten attribute

12: <&mut serde_json_wasm::ser::Serializer as serde::ser::Serializer>::serialize_map
             at /.../serde-json-wasm-0.2.1/src/ser/mod.rs:376
  13: cw20::query::_::<impl serde::ser::Serialize for cw20::query::AllowanceInfo>::serialize
             at packages/cw20/src/query.rs:71
  14: serde_json_wasm::ser::to_vec
             at /.../serde-json-wasm-0.2.1/src/ser/mod.rs:422
  15: cosmwasm_std::serde::to_vec
             at /.../cosmwasm-std-0.10.1/src/serde.rs:23
ethanfrey commented 4 years ago

Thank you for this issue and your research on the item. Good find

maurolacy commented 3 years ago

Not sure if strictly related to this, but I've noticed there's now map ser/de support in the upstream crate (serde-json-core).

I can integrate it if you think it's worth it / would help fix this.

therne commented 2 years ago

@ethanfrey now it's been a while since the upstream added map support, which means that flatten can be used (meaning a lot of CW codes can be refactored) — is there any plans to update it?

webmaster128 commented 1 year ago

Map support was just merged to main. In order to close this ticket, I think we should have explicit #[serde(flatten)] tests that show the input als Rust struct and the expected output as plain JSON.