fix(award): loosen AwardPageData and AwardMagazine for inconsistent Qobuz shapes
Matches Android's AwardDto where every field is nullable. Our struct required id and name as String which made /award/page fail parsing with 'missing field `id`' as soon as any award response deviated from the happy path (e.g. a deprecated award, an id returned as integer, or a reduced payload). All top-level AwardPageData fields are now Option; id + awarded_at accept string OR integer via a shared deserializer. AwardMagazine.id gets the same treatment. Frontend TS type matches the looser shape. cc
This commit is contained in:
2 files changed
+25
-6
No files matched your search
@@ -472,19 +472,26 @@ pub struct LabelPageGenericList {
|
||||
/// Magazine/publisher behind a press award.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AwardMagazine {
|
||||
#[serde(default, deserialize_with = "deserialize_string_or_int")]
|
||||
pub id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub name: Option<String>,
|
||||
#[serde(default)]
|
||||
pub image: Option<String>,
|
||||
}
|
||||
|
||||
/// Top-level response from /award/page.
|
||||
/// Top-level response from /award/page. Fields all Optional because
|
||||
/// Android's AwardDto marks everything nullable and Qobuz is loose
|
||||
/// about which ones come back on any given request.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AwardPageData {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
#[serde(default, deserialize_with = "deserialize_string_or_int")]
|
||||
pub id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub name: Option<String>,
|
||||
#[serde(default)]
|
||||
pub image: Option<String>,
|
||||
#[serde(default)]
|
||||
#[serde(default, deserialize_with = "deserialize_string_or_int")]
|
||||
pub awarded_at: Option<String>,
|
||||
#[serde(default)]
|
||||
pub magazine: Option<AwardMagazine>,
|
||||
@@ -496,6 +503,18 @@ pub struct AwardPageData {
|
||||
pub playlists: Option<AwardPageGenericList>,
|
||||
}
|
||||
|
||||
fn deserialize_string_or_int<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let value = Option::<serde_json::Value>::deserialize(deserializer)?;
|
||||
Ok(match value {
|
||||
Some(serde_json::Value::String(s)) => Some(s),
|
||||
Some(serde_json::Value::Number(n)) => Some(n.to_string()),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AwardPageContainer {
|
||||
pub id: Option<String>,
|
||||
|
||||
Reference in new issue
Block a user