Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fixed issues #926, and #928.
Added JsonConverter attributes to properties.
  • Loading branch information
Lewis-Fam committed Jan 23, 2024
commit 46a8c3799efd30dafc998be3ae04f1050f55bb33
19 changes: 19 additions & 0 deletions SpotifyAPI.Web/Models/Converters/DoubleToIntConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
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 Convert.ToInt32(reader.Value);
}
}
}
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