-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Due to Spotify API returning floats instead of uints for some fields of the Artist it cannot be parsed. This commit adds deserializing float values into u32 as a workaround. Related issue: [issue](#452) Signed-off-by: Maciej Torhan <[email protected]>
- Loading branch information
Showing
4 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Workaround for Spotify API bug which causes dome uint fields | ||
// being return as floats | ||
// TODO: remove this workaround after Spotify fix the [issue](https://github.com/ramsayleung/rspotify/issues/452) | ||
|
||
pub mod data_type_patcher { | ||
Check failure on line 5 in rspotify-model/src/data_type_patcher.rs
|
||
use serde::{Deserialize, Deserializer}; | ||
|
||
pub fn as_u32<'de, D>(deserializer: D) -> Result<u32, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let float_data: f64 = Deserialize::deserialize(deserializer)?; | ||
|
||
let u32_data = float_data as u32; | ||
|
||
Ok(u32_data) | ||
} | ||
|
||
pub fn as_some_u32<'de, D>(deserializer: D) -> Result<Option<u32>, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let float_data: Option<f64> = Deserialize::deserialize(deserializer)?; | ||
|
||
match float_data { | ||
Some(f) => return Ok(Some(f as u32)), | ||
Check failure on line 26 in rspotify-model/src/data_type_patcher.rs
|
||
None => return Ok(None), | ||
Check failure on line 27 in rspotify-model/src/data_type_patcher.rs
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
//! Image object | ||
pub use crate::data_type_patcher::data_type_patcher::as_some_u32; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Image object | ||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)] | ||
pub struct Image { | ||
// TODO: remove this statement after Spotify fix the [issue](https://github.com/ramsayleung/rspotify/issues/452) | ||
#[serde(deserialize_with = "as_some_u32")] | ||
pub height: Option<u32>, | ||
pub url: String, | ||
// TODO: remove this statement after Spotify fix the [issue](https://github.com/ramsayleung/rspotify/issues/452) | ||
#[serde(deserialize_with = "as_some_u32")] | ||
pub width: Option<u32>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters