Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deserialization of Smile maps with UUID keys #386

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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