diff --git a/src/de.rs b/src/de.rs index efae1d2..c7bbcd6 100644 --- a/src/de.rs +++ b/src/de.rs @@ -1,4 +1,4 @@ -use js_sys::{Array, ArrayBuffer, JsString, Number, Object, Symbol, Uint8Array}; +use js_sys::{Array, ArrayBuffer, JsString, Number, Object, Uint8Array}; use serde::de::value::{MapDeserializer, SeqDeserializer}; use serde::de::{self, IntoDeserializer}; use std::convert::TryFrom; @@ -314,19 +314,7 @@ impl<'de> de::Deserializer<'de> for Deserializer { // We need to handle this here because serde uses `deserialize_any` // for internally tagged enums visitor.visit_byte_buf(bytes) - } else if self.value.is_object() && - // The only reason we want to support objects here is because serde uses - // `deserialize_any` for internally tagged enums - // (see https://github.com/RReverser/serde-wasm-bindgen/pull/4#discussion_r352245020). - // - // We expect such enums to be represented via plain JS objects, so let's explicitly - // exclude Sets, Maps and any other iterables. These should be deserialized via concrete - // `deserialize_*` methods instead of us trying to guess the right target type. - // - // Hopefully we can rid of these hacks altogether once - // https://github.com/serde-rs/serde/issues/1183 is implemented / fixed on serde side. - !Symbol::iterator().js_in(&self.value) - { + } else if self.value.is_object() { self.deserialize_map(visitor) } else { self.invalid_type(visitor) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 4004716..35f2163 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -664,6 +664,18 @@ fn enums() { } } +#[wasm_bindgen_test] +fn serde_json_value() { + test_via_round_trip_with_config( + serde_json::from_str::("[0, \"foo\"]").unwrap(), + &SERIALIZER, + ); + test_via_round_trip_with_config( + serde_json::from_str::(r#"{"foo": "bar"}"#).unwrap(), + &SERIALIZER, + ); +} + #[wasm_bindgen_test] fn preserved_value() { #[derive(serde::Deserialize, serde::Serialize, PartialEq, Clone, Debug)]