From 17360042962dd07198a7c39aeee8d1fe85395cc3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Wed, 24 Apr 2024 10:14:33 +0200 Subject: [PATCH] deprecate compact serialization of some types Binary, HexBinary, Checksum --- packages/std/src/binary.rs | 12 ++++++++++-- packages/std/src/hex_binary.rs | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/std/src/binary.rs b/packages/std/src/binary.rs index bb65eea8db..7a2c30ce88 100644 --- a/packages/std/src/binary.rs +++ b/packages/std/src/binary.rs @@ -214,7 +214,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") + } } } @@ -224,7 +228,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") + } } } diff --git a/packages/std/src/hex_binary.rs b/packages/std/src/hex_binary.rs index aeb30b4c48..3a6f226a30 100644 --- a/packages/std/src/hex_binary.rs +++ b/packages/std/src/hex_binary.rs @@ -209,7 +209,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") + } } } @@ -219,7 +223,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") + } } }