Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions SpotifyAPI.Web/Models/Converters/DoubleToIntConverter.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
4 changes: 3 additions & 1 deletion SpotifyAPI.Web/Models/Response/Followers.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}

2 changes: 2 additions & 0 deletions SpotifyAPI.Web/Models/Response/FullArtist.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace SpotifyAPI.Web
{
Expand All @@ -11,6 +12,7 @@ public class FullArtist
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!;
Expand Down
1 change: 1 addition & 0 deletions SpotifyAPI.Web/Models/Response/FullTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class FullTrack : IPlayableItem
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!;
Expand Down
4 changes: 4 additions & 0 deletions SpotifyAPI.Web/Models/Response/Image.cs
Original file line number Diff line number Diff line change
@@ -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!;
}
Expand Down