CosmWasm / serde-json-wasm

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

serializing tuples failes and deserializing tuples causes panics #19

Closed reuvenpo closed 3 years ago

reuvenpo commented 4 years ago

This is similar to #18

given a type definition:

#[derive(Serialize, Deserialize)]
enum MyType {
  Add(i32, i32)
}

running this code:

println!("{:?}", serde_json_wasm::from_slice::<MyType>(b"{\"add\":[2, 3}"));

throws panics from: (partial stack trace)

12: <&mut serde_json_wasm::ser::Serializer as serde::ser::Serializer>::serialize_tuple_variant
13: example_contract::contract::_::<impl serde::ser::Serialize for example_contract::contract::QueryMsg>::serialize
14: serde_json_wasm::ser::to_string

running this code:

println!("{}", serde_json_wasm::to_string(&MyType::Add(3, 4)).unwrap_or_else(|err| err.to_string()));

shows:

Err(InvalidType)
maurolacy commented 3 years ago

I'll take a look at this.