Function activitypub_federation::protocol::helpers::deserialize_one
source ยท pub fn deserialize_one<'de, T, D>(deserializer: D) -> Result<[T; 1], D::Error>where
T: Deserialize<'de>,
D: Deserializer<'de>,
Expand description
Deserialize JSON single value or single element array into single value.
Useful if your application can only handle a single value for a field, but another federated platform sends single value wrapped in array. Fails if array contains multiple items.
#[derive(serde::Deserialize)]
struct Note {
#[serde(deserialize_with = "deserialize_one")]
to: [Url; 1]
}
let note = serde_json::from_str::<Note>(r#"{"to": ["https://example.com/u/alice"] }"#);
assert!(note.is_ok());