Fixed issues #926, and #928. (#942)

* Fixed issues #926, and #928.
Added JsonConverter attributes to properties.

* Fixed complier warning CA1305
This commit is contained in:
Lewis-Fam 2024-02-10 03:03:22 -07:00 committed by GitHub
parent 0fe33df65a
commit 9dbd210a2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,21 @@
using System;
using System.Globalization;
using Newtonsoft.Json;
namespace SpotifyAPI.Web
{
public class DoubleToIntConverter : JsonConverter<int>
{
public override void WriteJson(JsonWriter? writer, int value, JsonSerializer serializer)
{
writer?.WriteValue(value);
}
public override int ReadJson(JsonReader? reader, Type objectType, int existingValue, bool hasExistingValue,
JsonSerializer serializer)
{
return reader != null ? Convert.ToInt32(reader.Value, CultureInfo.InvariantCulture) : 0;
}
}
}

View File

@ -1,10 +1,12 @@
using Newtonsoft.Json;
namespace SpotifyAPI.Web
{
public class Followers
{
public string Href { get; set; } = default!;
[JsonConverter(typeof(DoubleToIntConverter))]
public int Total { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using Newtonsoft.Json;
namespace SpotifyAPI.Web
{
@ -11,6 +12,7 @@ namespace SpotifyAPI.Web
public string Id { get; set; } = default!;
public List<Image> Images { get; set; } = default!;
public string Name { get; set; } = default!;
[JsonConverter(typeof(DoubleToIntConverter))]
public int Popularity { get; set; }
public string Type { get; set; } = default!;
public string Uri { get; set; } = default!;

View File

@ -10,6 +10,7 @@ namespace SpotifyAPI.Web
public List<SimpleArtist> Artists { get; set; } = default!;
public List<string> AvailableMarkets { get; set; } = default!;
public int DiscNumber { get; set; }
[JsonConverter(typeof(DoubleToIntConverter))]
public int DurationMs { get; set; }
public bool Explicit { get; set; }
public Dictionary<string, string> ExternalIds { get; set; } = default!;

View File

@ -1,8 +1,12 @@
using Newtonsoft.Json;
namespace SpotifyAPI.Web
{
public class Image
{
[JsonConverter(typeof(DoubleToIntConverter))]
public int Height { get; set; }
[JsonConverter(typeof(DoubleToIntConverter))]
public int Width { get; set; }
public string Url { get; set; } = default!;
}