Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deserialize empty images from null #480

Merged

Conversation

plustik
Copy link

@plustik plustik commented Apr 29, 2024

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 #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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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
Copy link

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

@amittamari
Copy link

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

Reading through the issue seems like it wouldn't work:
#459 (comment)

@plustik
Copy link
Author

plustik commented Apr 29, 2024

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 ramsayleung merged commit fade9d9 into ramsayleung:master May 2, 2024
7 checks passed
@ramsayleung
Copy link
Owner

Thanks for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants