diff --git a/CHANGELOG.md b/CHANGELOG.md index ca12c32e53..4d4301180f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,8 @@ and this project adheres to - cosmwasm-schema: `#[cw_serde]` now doesn't add `#[serde(deny_unknown_fields)]` to the expanded code anymore ([#2080]) - cosmwasm-std: Improve performance of `Uint{64,128,256,512}::isqrt` ([#2108]) +- cosmwasm-std: Deprecate "compact" serialization of `Binary`, `HexBinary`, + `Checksum` ([#2125]) [#2044]: https://github.com/CosmWasm/cosmwasm/pull/2044 [#2051]: https://github.com/CosmWasm/cosmwasm/pull/2051 @@ -60,6 +62,7 @@ and this project adheres to [#2070]: https://github.com/CosmWasm/cosmwasm/pull/2070 [#2080]: https://github.com/CosmWasm/cosmwasm/pull/2080 [#2108]: https://github.com/CosmWasm/cosmwasm/pull/2108 +[#2125]: https://github.com/CosmWasm/cosmwasm/pull/2125 ## [2.0.1] - 2024-04-03 diff --git a/packages/core/src/binary.rs b/packages/core/src/binary.rs index 1d445c7a5a..7564916240 100644 --- a/packages/core/src/binary.rs +++ b/packages/core/src/binary.rs @@ -209,7 +209,11 @@ impl Serialize for Binary { where S: ser::Serializer, { - serializer.serialize_str(&self.to_base64()) + if serializer.is_human_readable() { + serializer.serialize_str(&self.to_base64()) + } else { + panic!("Binary is only intended to be used with JSON serialization for now. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.") + } } } @@ -219,7 +223,11 @@ impl<'de> Deserialize<'de> for Binary { where D: Deserializer<'de>, { - deserializer.deserialize_str(Base64Visitor) + if deserializer.is_human_readable() { + deserializer.deserialize_str(Base64Visitor) + } else { + panic!("Binary is only intended to be used with JSON serialization for now. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.") + } } } diff --git a/packages/core/src/hex_binary.rs b/packages/core/src/hex_binary.rs index f55a8daeae..bce0df2179 100644 --- a/packages/core/src/hex_binary.rs +++ b/packages/core/src/hex_binary.rs @@ -212,7 +212,11 @@ impl Serialize for HexBinary { where S: ser::Serializer, { - serializer.serialize_str(&self.to_hex()) + if serializer.is_human_readable() { + serializer.serialize_str(&self.to_hex()) + } else { + panic!("HexBinary is only intended to be used with JSON serialization for now. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.") + } } } @@ -222,7 +226,11 @@ impl<'de> Deserialize<'de> for HexBinary { where D: Deserializer<'de>, { - deserializer.deserialize_str(HexVisitor) + if deserializer.is_human_readable() { + deserializer.deserialize_str(HexVisitor) + } else { + panic!("HexBinary is only intended to be used with JSON serialization for now. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.") + } } } diff --git a/packages/std/src/checksum.rs b/packages/std/src/checksum.rs index e56735640d..b2b1a79e9a 100644 --- a/packages/std/src/checksum.rs +++ b/packages/std/src/checksum.rs @@ -71,7 +71,11 @@ impl Serialize for Checksum { where S: ser::Serializer, { - serializer.serialize_str(&self.to_hex()) + if serializer.is_human_readable() { + serializer.serialize_str(&self.to_hex()) + } else { + panic!("Checksum is only intended to be used with JSON serialization for now. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.") + } } } @@ -81,7 +85,11 @@ impl<'de> Deserialize<'de> for Checksum { where D: Deserializer<'de>, { - deserializer.deserialize_str(ChecksumVisitor) + if deserializer.is_human_readable() { + deserializer.deserialize_str(ChecksumVisitor) + } else { + panic!("Checksum is only intended to be used with JSON serialization for now. If you are hitting this panic please open an issue at https://github.com/CosmWasm/cosmwasm describing your use case.") + } } }