diff --git a/crates/console/Cargo.toml b/crates/console/Cargo.toml index 88788aa9..ea3264bf 100644 --- a/crates/console/Cargo.toml +++ b/crates/console/Cargo.toml @@ -12,9 +12,10 @@ documentation = "https://docs.rs/gloo-console/" categories = ["api-bindings", "development-tools::profiling", "wasm"] [dependencies] -wasm-bindgen = { version = "0.2", features = ["serde-serialize"] } +wasm-bindgen = "0.2" js-sys = "0.3" serde = { version = "1", features = ["derive"] } +serde_json = "1.0" [dependencies.web-sys] version = "0.3" features = [ diff --git a/crates/console/src/lib.rs b/crates/console/src/lib.rs index 8393676d..d896013f 100644 --- a/crates/console/src/lib.rs +++ b/crates/console/src/lib.rs @@ -38,7 +38,7 @@ pub mod __macro { data: impl serde::Serialize, columns: impl IntoIterator, ) { - let data = JsValue::from_serde(&data).unwrap_throw(); + let data = js_sys::JSON::parse(&serde_json::to_string(&data).unwrap_throw()).unwrap_throw(); let columns = columns.into_iter().map(JsValue::from_str).collect(); crate::externs::table_with_data_and_columns(data, columns); diff --git a/crates/net/Cargo.toml b/crates/net/Cargo.toml index 2ce35d0b..337e54d4 100644 --- a/crates/net/Cargo.toml +++ b/crates/net/Cargo.toml @@ -40,7 +40,7 @@ futures = "0.3" default = ["json", "websocket", "http"] # Enables `.json()` on `Response` -json = ["wasm-bindgen/serde-serialize", "serde", "serde_json"] +json = ["serde", "serde_json"] # Enables the WebSocket API websocket = [ 'web-sys/WebSocket', diff --git a/crates/net/src/http/mod.rs b/crates/net/src/http/mod.rs index 5c3e9ebb..31524e0f 100644 --- a/crates/net/src/http/mod.rs +++ b/crates/net/src/http/mod.rs @@ -391,9 +391,16 @@ impl Response { #[cfg_attr(docsrs, doc(cfg(feature = "json")))] pub async fn json(&self) -> Result { let promise = self.response.json().map_err(js_to_error)?; - let json = JsFuture::from(promise).await.map_err(js_to_error)?; - - Ok(json.into_serde()?) + let json = JsFuture::from(promise) + .await + .map_err(js_to_error) + .and_then(|json| { + js_sys::JSON::stringify(&json) + .map(String::from) + .map_err(js_to_error) + })?; + + Ok(serde_json::from_str(&json)?) } /// Reads the response as a String. diff --git a/crates/net/src/websocket/futures.rs b/crates/net/src/websocket/futures.rs index 9f08178a..e84be415 100644 --- a/crates/net/src/websocket/futures.rs +++ b/crates/net/src/websocket/futures.rs @@ -102,15 +102,17 @@ impl WebSocket { url: &str, protocols: &[S], ) -> Result { - Self::setup(web_sys::WebSocket::new_with_str_sequence( - url, - &JsValue::from_serde(protocols).map_err(|err| { - js_sys::Error::new(&format!( - "Failed to convert protocols to Javascript value: {}", - err - )) - })?, - )) + let map_err = |err| { + js_sys::Error::new(&format!( + "Failed to convert protocols to Javascript value: {}", + err + )) + }; + let json = serde_json::to_string(protocols) + .map_err(|e| map_err(e.to_string())) + .map(|d| js_sys::JSON::parse(&d).unwrap_throw())?; + + Self::setup(web_sys::WebSocket::new_with_str_sequence(url, &json)) } fn setup(ws: Result) -> Result { diff --git a/crates/storage/Cargo.toml b/crates/storage/Cargo.toml index 7aeed38d..b0f599ef 100644 --- a/crates/storage/Cargo.toml +++ b/crates/storage/Cargo.toml @@ -11,7 +11,7 @@ homepage = "https://github.com/rustwasm/gloo" categories = ["api-bindings", "storage", "wasm"] [dependencies] -wasm-bindgen = { version = "0.2", features = ["serde-serialize"] } +wasm-bindgen = "0.2" serde = "1.0" serde_json = "1.0" thiserror = "1.0"