diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b730dd127..da132ece0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ and this project adheres to ## [Unreleased] +### Changed + +- cosmwasm-std: Deprecate "compact" serialization of `Binary`, `HexBinary`, + `Checksum` ([#2128]) + +[#2128]: https://github.com/CosmWasm/cosmwasm/pull/2128 + ## [2.0.2] - 2024-04-24 ### Fixed diff --git a/packages/std/src/binary.rs b/packages/std/src/binary.rs index 8237980666..0de5d55b23 100644 --- a/packages/std/src/binary.rs +++ b/packages/std/src/binary.rs @@ -220,7 +220,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.") + } } } @@ -230,7 +234,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/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.") + } } } diff --git a/packages/std/src/hex_binary.rs b/packages/std/src/hex_binary.rs index 1b704e2261..4c31260257 100644 --- a/packages/std/src/hex_binary.rs +++ b/packages/std/src/hex_binary.rs @@ -210,7 +210,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.") + } } } @@ -220,7 +224,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.") + } } }