ramsayleung / rspotify

Spotify Web API SDK implemented on Rust
MIT License
632 stars 121 forks source link

fix: deserialize empty images from null #480

Closed plustik closed 4 months ago

plustik commented 4 months ago

Description

Adjust the derived implementation of Deserialize for SimplifiedPlaylist. Instead of returning an error when deserializing the value null for the field images, this value is deserialized to an empty Vec. This is necessary, because the Spotify-API is returning null instead of an empty array for this field in some instances.

Motivation and Context

This fixes the problem described in https://github.com/ramsayleung/rspotify/issues/459. The Spotify-API is returning null instead of an empty array for the images-field in some instances.

Dependencies

None

Type of change

Please delete options that are not relevant.

How has this been tested?

The change was tested by using the patched version of rspotify in this project.

Is this change properly documented?

I don't think this needs to be documented. The change won't affect the behavior of rspotify when the Spotify-API returns images: []. When the Spotify-API returns images: null current_user_playlists wasn't usable prior to this change. In this case the PR implements the expected behavior.

FichteFoll commented 4 months ago

Would just using #[serde(default)] also work? https://serde.rs/attr-default.html

amittamari commented 4 months ago

Would just using #[serde(default)] also work? https://serde.rs/attr-default.html

Reading through the issue seems like it wouldn't work: https://github.com/ramsayleung/rspotify/issues/459#issuecomment-2025391563

plustik commented 4 months ago

Would just using #[serde(default)] also work? https://serde.rs/attr-default.html

#[serde(default)] would not work. This is also discussed here. The workaround given there is almost the same as the one I copied from here.

ramsayleung commented 4 months ago

Thanks for your contribution.