From e41a7f701485d345d16e51ef74750976e45727d0 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 30 Mar 2023 16:41:14 +0100 Subject: [PATCH] Fix simple serialization of sequences and maps --- lib/src/sql/array.rs | 7 ++++++- lib/src/sql/object.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/sql/array.rs b/lib/src/sql/array.rs index d9182ffd..02b272eb 100644 --- a/lib/src/sql/array.rs +++ b/lib/src/sql/array.rs @@ -14,6 +14,7 @@ use crate::sql::value::{value, Value}; use nom::character::complete::char; use nom::combinator::opt; use nom::multi::separated_list0; +use serde::ser::SerializeSeq; use serde::{Deserialize, Serialize}; use std::collections::HashSet; use std::fmt::{self, Display, Formatter, Write}; @@ -167,7 +168,11 @@ impl Serialize for Array { if is_internal_serialization() { serializer.serialize_newtype_struct(TOKEN, &self.0) } else { - serializer.serialize_some(&self.to_string()) + let mut arr = serializer.serialize_seq(Some(self.len()))?; + for v in &self.0 { + arr.serialize_element(v)?; + } + arr.end() } } } diff --git a/lib/src/sql/object.rs b/lib/src/sql/object.rs index 0dbcd9fe..fdfac3cc 100644 --- a/lib/src/sql/object.rs +++ b/lib/src/sql/object.rs @@ -175,7 +175,7 @@ impl Serialize for Object { serializer.serialize_newtype_struct(TOKEN, &self.0) } else { let mut map = serializer.serialize_map(Some(self.len()))?; - for (ref k, ref v) in &self.0 { + for (k, v) in &self.0 { map.serialize_key(k)?; map.serialize_value(v)?; }