From ab8b21d01ca85a2e940e7bfe9bbd942ca5278125 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Fri, 12 Sep 2025 13:00:11 -0500 Subject: [PATCH] Fix deserialization with some attributes The "repository" field doesn't have a type right now, so I'm going to skip deserializing it. The returned JSON has a value for this field, but Serde will ignore it. The `Packages.pkg_type` field is called "type" in the JSON string (and Go code, as mentioned in the comment). Similarly, the PackageType enum I have to represent this field in Rust has capital starting letters where the JSON uses all lowercase. Both problems are solved with a Serde rename attribute. --- src/structs/package.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/structs/package.rs b/src/structs/package.rs index 2d3e76c..d7631e2 100644 --- a/src/structs/package.rs +++ b/src/structs/package.rs @@ -14,8 +14,10 @@ pub struct Package { id: u64, name: String, owner: Author, + #[serde(skip)] repository: (), // TODO: Create a `struct Repository` - pkg_type: PackageType, // field is "type" in Go, but that's a keyword in Rust. + #[serde(rename = "type")] // field is "type" in JSON & Go, but that's a + pkg_type: PackageType, // keyword in Rust so we need to serde-rename it. version: String, } @@ -37,6 +39,7 @@ impl Package { /// A marker for the kind of package being handled. #[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] pub enum PackageType { Alpine, Arch,