Skip to content

Commit

Permalink
Merge pull request #386 from palantir/fix-smile-uuid-key
Browse files Browse the repository at this point in the history
Fix deserialization of Smile maps with UUID keys
  • Loading branch information
sfackler authored Sep 18, 2024
2 parents 51df424 + 7af550b commit 94d6b3e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-386.v2.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion conjure-serde/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, B> {
Expand Down Expand Up @@ -341,7 +348,7 @@ where
}

fn is_human_readable(&self) -> bool {
self.inner.is_human_readable()
B::is_human_readable(&self.inner)
}
}

Expand Down
7 changes: 7 additions & 0 deletions conjure-serde/src/de/unknown_fields_behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions conjure-serde/src/json/de/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 17 additions & 1 deletion conjure-serde/src/smile/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 94d6b3e

Please sign in to comment.