public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox] schema: ser: fix value serialization for maps
Date: Thu, 26 Mar 2026 17:46:30 +0100	[thread overview]
Message-ID: <20260326165515.2234618-1-c.heiss@proxmox.com> (raw)

.. by actually serializing map values as values, not keys.

Call the correct .do_value() instead of .do_key() in
SerializeStruct::serialize_value().

Without, the included test case would produce "a=,1=" instead of the
expected "a=1"

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-schema/src/property_string.rs | 17 +++++++++++++++++
 proxmox-schema/src/ser/mod.rs         |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/proxmox-schema/src/property_string.rs b/proxmox-schema/src/property_string.rs
index 6e4b3248..fc52c895 100644
--- a/proxmox-schema/src/property_string.rs
+++ b/proxmox-schema/src/property_string.rs
@@ -367,6 +367,7 @@ where
 #[cfg(test)]
 mod test {
     use serde::{Deserialize, Serialize};
+    use std::collections::HashMap;
 
     use crate::schema::*;
 
@@ -515,4 +516,20 @@ mod test {
 
         Ok(())
     }
+
+    #[test]
+    fn test_map_serialization() {
+        #[derive(Serialize, PartialEq)]
+        struct Outer(HashMap<String, u32>);
+
+        impl ApiType for Outer {
+            const API_SCHEMA: Schema = ObjectSchema::new("Outer", &[])
+                .additional_properties(true)
+                .schema();
+        }
+
+        let mut map = HashMap::with_capacity(2);
+        map.insert("a".to_owned(), 1);
+        assert_eq!(super::print(&Outer(map)).expect("property string"), "a=1");
+    }
 }
diff --git a/proxmox-schema/src/ser/mod.rs b/proxmox-schema/src/ser/mod.rs
index e19209a8..0a91b13c 100644
--- a/proxmox-schema/src/ser/mod.rs
+++ b/proxmox-schema/src/ser/mod.rs
@@ -284,7 +284,7 @@ impl<T: fmt::Write> ser::SerializeMap for SerializeStruct<T> {
     where
         V: Serialize + ?Sized,
     {
-        self.do_key(value)
+        self.do_value(value)
     }
 
     fn end(self) -> Result<Self::Ok, Self::Error> {
-- 
2.53.0





             reply	other threads:[~2026-03-26 16:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-26 16:46 Christoph Heiss [this message]
2026-03-27 15:24 ` Wolfgang Bumiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260326165515.2234618-1-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal