Skip to content

Commit

Permalink
Merge pull request #480 from plustik/fix/serializing-null-images
Browse files Browse the repository at this point in the history
fix: deserialize empty images from null
  • Loading branch information
ramsayleung authored May 2, 2024
2 parents a651e27 + cc507a8 commit fade9d9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rspotify-model/src/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ pub struct PlaylistTracksRef {
pub total: u32,
}

fn deserialize_null_default<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
T: Default + serde::Deserialize<'de>,
D: serde::Deserializer<'de>,
{
Ok(Option::deserialize(deserializer)?.unwrap_or_default())
}

/// Simplified playlist object
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct SimplifiedPlaylist {
pub collaborative: bool,
pub external_urls: HashMap<String, String>,
pub href: String,
pub id: PlaylistId<'static>,
#[serde(deserialize_with = "deserialize_null_default")]
pub images: Vec<Image>,
pub name: String,
pub owner: PublicUser,
Expand Down

0 comments on commit fade9d9

Please sign in to comment.