deserialize_empty_string_as_none

Function deserialize_empty_string_as_none 

Source
pub fn deserialize_empty_string_as_none<'de, D>(
    deserializer: D,
) -> Result<Option<String>, D::Error>
where D: Deserializer<'de>,
Expand description

Deserializes an empty string into None.

OKX frequently represents null string fields as an empty string (""). When such a payload is mapped onto Option<String> the default behaviour would yield Some(""), which is semantically different from the intended absence of a value. Applying this helper via

#[serde(deserialize_with = "crate::common::parse::deserialize_empty_string_as_none")]
pub cl_ord_id: Option<String>,

ensures that empty strings are normalised to None during deserialization.

ยงErrors

Returns an error if the JSON value cannot be deserialised into a string.