Skip to content

Commit 9dbd210

Browse files
authored
Fixed issues #926, and #928. (#942)
* Fixed issues #926, and #928. Added JsonConverter attributes to properties. * Fixed complier warning CA1305
1 parent 0fe33df commit 9dbd210

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Globalization;
3+
4+
using Newtonsoft.Json;
5+
6+
namespace SpotifyAPI.Web
7+
{
8+
public class DoubleToIntConverter : JsonConverter<int>
9+
{
10+
public override void WriteJson(JsonWriter? writer, int value, JsonSerializer serializer)
11+
{
12+
writer?.WriteValue(value);
13+
}
14+
15+
public override int ReadJson(JsonReader? reader, Type objectType, int existingValue, bool hasExistingValue,
16+
JsonSerializer serializer)
17+
{
18+
return reader != null ? Convert.ToInt32(reader.Value, CultureInfo.InvariantCulture) : 0;
19+
}
20+
}
21+
}

SpotifyAPI.Web/Models/Response/Followers.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
using Newtonsoft.Json;
2+
13
namespace SpotifyAPI.Web
24
{
35
public class Followers
46
{
57
public string Href { get; set; } = default!;
68

9+
[JsonConverter(typeof(DoubleToIntConverter))]
710
public int Total { get; set; }
811
}
912
}
10-

SpotifyAPI.Web/Models/Response/FullArtist.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using Newtonsoft.Json;
23

34
namespace SpotifyAPI.Web
45
{
@@ -11,6 +12,7 @@ public class FullArtist
1112
public string Id { get; set; } = default!;
1213
public List<Image> Images { get; set; } = default!;
1314
public string Name { get; set; } = default!;
15+
[JsonConverter(typeof(DoubleToIntConverter))]
1416
public int Popularity { get; set; }
1517
public string Type { get; set; } = default!;
1618
public string Uri { get; set; } = default!;

SpotifyAPI.Web/Models/Response/FullTrack.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class FullTrack : IPlayableItem
1010
public List<SimpleArtist> Artists { get; set; } = default!;
1111
public List<string> AvailableMarkets { get; set; } = default!;
1212
public int DiscNumber { get; set; }
13+
[JsonConverter(typeof(DoubleToIntConverter))]
1314
public int DurationMs { get; set; }
1415
public bool Explicit { get; set; }
1516
public Dictionary<string, string> ExternalIds { get; set; } = default!;

SpotifyAPI.Web/Models/Response/Image.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
using Newtonsoft.Json;
2+
13
namespace SpotifyAPI.Web
24
{
35
public class Image
46
{
7+
[JsonConverter(typeof(DoubleToIntConverter))]
58
public int Height { get; set; }
9+
[JsonConverter(typeof(DoubleToIntConverter))]
610
public int Width { get; set; }
711
public string Url { get; set; } = default!;
812
}

0 commit comments

Comments
 (0)