From 2d1b91b9af7148fcc423244a7c7cf80298fbf8e1 Mon Sep 17 00:00:00 2001 From: Diane Huxley Date: Fri, 8 Dec 2023 12:13:10 -0800 Subject: [PATCH] Don't serialize None --- crates/protocol/Cargo.toml | 3 ++- crates/protocol/src/message/close.rs | 2 ++ crates/protocol/src/message/order_status.rs | 1 - crates/protocol/src/message/quote.rs | 6 ++++++ crates/protocol/src/resource/offering.rs | 3 +++ 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/protocol/Cargo.toml b/crates/protocol/Cargo.toml index d645970a..395de155 100644 --- a/crates/protocol/Cargo.toml +++ b/crates/protocol/Cargo.toml @@ -13,4 +13,5 @@ jsonschema = "0.17.1" serde = { version = "1.0.193", features = ["derive"] } serde_json = "1.0.108" type-safe-id = { version = "0.2.1", features = ["serde"] } -thiserror = "1.0.50" \ No newline at end of file +thiserror = "1.0.50" +serde_with = "3.4.0" diff --git a/crates/protocol/src/message/close.rs b/crates/protocol/src/message/close.rs index 2e0a01b2..2a44bff5 100644 --- a/crates/protocol/src/message/close.rs +++ b/crates/protocol/src/message/close.rs @@ -1,5 +1,6 @@ use ::serde::{Deserialize, Serialize}; use chrono::Utc; +use serde_with::skip_serializing_none; use type_safe_id::{DynamicType, TypeSafeId}; use super::{Message, MessageError, MessageKind, MessageMetadata}; @@ -37,6 +38,7 @@ impl Close { /// See [Quote](https://github.com/TBD54566975/tbdex/tree/main/specs/protocol#close) for more /// information. #[derive(Debug, Deserialize, PartialEq, Serialize)] +#[skip_serializing_none] #[serde(rename_all = "camelCase")] pub struct CloseData { /// an explanation of why the exchange is being closed/completed diff --git a/crates/protocol/src/message/order_status.rs b/crates/protocol/src/message/order_status.rs index 06ccd3f4..e5c2827f 100644 --- a/crates/protocol/src/message/order_status.rs +++ b/crates/protocol/src/message/order_status.rs @@ -43,7 +43,6 @@ impl OrderStatus { #[serde(rename_all = "camelCase")] pub struct OrderStatusData { /// Current status of Order that's being executed - order_status: String, } diff --git a/crates/protocol/src/message/quote.rs b/crates/protocol/src/message/quote.rs index b02e2d88..8ca193f3 100644 --- a/crates/protocol/src/message/quote.rs +++ b/crates/protocol/src/message/quote.rs @@ -1,5 +1,6 @@ use ::serde::{Deserialize, Serialize}; use chrono::{DateTime, Utc}; +use serde_with::skip_serializing_none; use type_safe_id::{DynamicType, TypeSafeId}; use super::{Message, MessageError, MessageKind, MessageMetadata}; @@ -35,6 +36,7 @@ impl Quote { /// See [Quote](https://github.com/TBD54566975/tbdex/tree/main/specs/protocol#quote) for more /// information. #[derive(Debug, Deserialize, PartialEq, Serialize)] +#[skip_serializing_none] #[serde(rename_all = "camelCase")] pub struct QuoteData { /// When this quote expires. Expressed as ISO8601 @@ -48,6 +50,7 @@ pub struct QuoteData { } #[derive(Debug, Deserialize, PartialEq, Serialize)] +#[skip_serializing_none] #[serde(rename_all = "camelCase")] pub struct QuoteDetails { /// ISO 3166 currency code string @@ -59,6 +62,7 @@ pub struct QuoteDetails { } #[derive(Debug, Deserialize, PartialEq, Serialize)] +#[skip_serializing_none] #[serde(rename_all = "camelCase")] pub struct PaymentInstructions { /// Link or Instruction describing how to pay the PFI. @@ -68,6 +72,8 @@ pub struct PaymentInstructions { } #[derive(Debug, Deserialize, PartialEq, Serialize)] +#[skip_serializing_none] + #[serde(rename_all = "camelCase")] pub struct PaymentInstruction { /// Link or Instruction describing how to pay the PFI. diff --git a/crates/protocol/src/resource/offering.rs b/crates/protocol/src/resource/offering.rs index 2d3787bf..0c9c7b23 100644 --- a/crates/protocol/src/resource/offering.rs +++ b/crates/protocol/src/resource/offering.rs @@ -4,6 +4,7 @@ use credentials::pex::v2::PresentationDefinition; use jsonschema::{Draft, JSONSchema}; use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue; +use serde_with::skip_serializing_none; /// Struct that interacts with an [`Offering`] [`Resource`] pub struct Offering; @@ -55,6 +56,7 @@ pub struct OfferingData { } #[derive(Debug, Default, Deserialize, PartialEq, Serialize)] +#[skip_serializing_none] #[serde(rename_all = "camelCase")] pub struct CurrencyDetails { /// ISO 3166 currency code string @@ -66,6 +68,7 @@ pub struct CurrencyDetails { } #[derive(Debug, Default, Deserialize, PartialEq, Serialize)] +#[skip_serializing_none] #[serde(rename_all = "camelCase")] pub struct PaymentMethod { /// Type of payment method (i.e. `DEBIT_CARD`, `BITCOIN_ADDRESS`, `SQUARE_PAY`)