From b00231540ea9c5ad37c52e5ebdb6d10fb60a1291 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Wed, 18 Sep 2024 10:25:13 -0400 Subject: [PATCH 1/3] Fix deserialization of Smile maps with UUID keys --- conjure-serde/src/de/mod.rs | 9 ++++++++- conjure-serde/src/de/unknown_fields_behavior.rs | 7 +++++++ conjure-serde/src/json/de/client.rs | 8 ++++++++ conjure-serde/src/smile/test.rs | 10 +++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/conjure-serde/src/de/mod.rs b/conjure-serde/src/de/mod.rs index 31ef5dd1..4b93e94a 100644 --- a/conjure-serde/src/de/mod.rs +++ b/conjure-serde/src/de/mod.rs @@ -190,6 +190,13 @@ pub trait Behavior { { de.deserialize_struct(name, fields, visitor) } + + fn is_human_readable<'de, D>(de: &D) -> bool + where + D: Deserializer<'de>, + { + de.is_human_readable() + } } pub struct Override { @@ -341,7 +348,7 @@ where } fn is_human_readable(&self) -> bool { - self.inner.is_human_readable() + B::is_human_readable(&self.inner) } } diff --git a/conjure-serde/src/de/unknown_fields_behavior.rs b/conjure-serde/src/de/unknown_fields_behavior.rs index 58ee35d0..856eb439 100644 --- a/conjure-serde/src/de/unknown_fields_behavior.rs +++ b/conjure-serde/src/de/unknown_fields_behavior.rs @@ -88,6 +88,13 @@ where DelegatingVisitor::new(StructVisitor { fields }, visitor), ) } + + fn is_human_readable<'de, D>(de: &D) -> bool + where + D: Deserializer<'de>, + { + B::is_human_readable(de) + } } struct StructVisitor { diff --git a/conjure-serde/src/json/de/client.rs b/conjure-serde/src/json/de/client.rs index c3dac8e5..6ade82c8 100644 --- a/conjure-serde/src/json/de/client.rs +++ b/conjure-serde/src/json/de/client.rs @@ -187,6 +187,14 @@ impl Behavior for KeyBehavior { { de.deserialize_str(ByteBufVisitor(visitor)) } + + // We don't need this for JSON, but it allows the Smile logic to work with this KeyBehavior + fn is_human_readable<'de, D>(_: &D) -> bool + where + D: de::Deserializer<'de>, + { + true + } } macro_rules! float_visitor { diff --git a/conjure-serde/src/smile/test.rs b/conjure-serde/src/smile/test.rs index f8da139f..f5d5e2ae 100644 --- a/conjure-serde/src/smile/test.rs +++ b/conjure-serde/src/smile/test.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use conjure_object::DoubleKey; +use conjure_object::{DoubleKey, Uuid}; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use serde_bytes::ByteBuf; @@ -129,3 +129,11 @@ fn server_unknown_fields() { assert!(e.to_string().contains("foo")); assert!(e.to_string().contains("bogus")); } + +#[test] +fn uuid_keys() { + test_serde( + &BTreeMap::from([(Uuid::nil(), 1)]), + b":)\n\x05\xfa\xa300000000-0000-0000-0000-000000000000\xc2\xfb", + ); +} From a3481e4432ca61813c6bbf9d1f62e4a887214010 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Wed, 18 Sep 2024 10:31:16 -0400 Subject: [PATCH 2/3] also test uuid values --- conjure-serde/src/smile/test.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/conjure-serde/src/smile/test.rs b/conjure-serde/src/smile/test.rs index f5d5e2ae..65d6ffa3 100644 --- a/conjure-serde/src/smile/test.rs +++ b/conjure-serde/src/smile/test.rs @@ -109,6 +109,22 @@ fn double_keys() { ) } +#[test] +fn uuid_keys() { + test_serde( + &BTreeMap::from([(Uuid::nil(), 1)]), + b":)\n\x05\xfa\xa300000000-0000-0000-0000-000000000000\xc2\xfb", + ); +} + +#[test] +fn uuid_values() { + test_serde( + &Uuid::nil(), + b":)\n\x05\xfd\x90\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + ) +} + #[derive(Serialize, Deserialize, Debug, PartialEq)] struct Foo { foo: i32, @@ -129,11 +145,3 @@ fn server_unknown_fields() { assert!(e.to_string().contains("foo")); assert!(e.to_string().contains("bogus")); } - -#[test] -fn uuid_keys() { - test_serde( - &BTreeMap::from([(Uuid::nil(), 1)]), - b":)\n\x05\xfa\xa300000000-0000-0000-0000-000000000000\xc2\xfb", - ); -} From 7af550b728907b59ea74073c93b7943759a05eb9 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Wed, 18 Sep 2024 14:33:24 +0000 Subject: [PATCH 3/3] Add generated changelog entries --- changelog/@unreleased/pr-386.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-386.v2.yml diff --git a/changelog/@unreleased/pr-386.v2.yml b/changelog/@unreleased/pr-386.v2.yml new file mode 100644 index 00000000..3504aba8 --- /dev/null +++ b/changelog/@unreleased/pr-386.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: Fix deserialization of Smile maps with UUID keys + links: + - https://github.com/palantir/conjure-rust/pull/386