From 6b6053bf162bb73e2fb02207d637dc9f494376ba Mon Sep 17 00:00:00 2001 From: FX Date: Sun, 16 Apr 2023 15:00:19 +0200 Subject: [PATCH] Make project not error on start The deserialization of the update information error'ed because the deserialization models mixed Newtonsoft.Json models with System.Text.Json models. --- LeagueBroadcast.Common/Http/RestRequester.cs | 23 +++----------------- LeagueBroadcast.Update/GitHubReleaseInfo.cs | 14 ++++++------ 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/LeagueBroadcast.Common/Http/RestRequester.cs b/LeagueBroadcast.Common/Http/RestRequester.cs index 768ec17..473bb96 100644 --- a/LeagueBroadcast.Common/Http/RestRequester.cs +++ b/LeagueBroadcast.Common/Http/RestRequester.cs @@ -2,12 +2,8 @@ using System.Net.Http.Headers; using System.Net.Http; using System.Threading.Tasks; -using System.Text.Json; -using System.Text.Json.Serialization; using LeagueBroadcast.Common; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; +using Newtonsoft.Json; namespace LeagueBroadcast.Update.Http { @@ -42,7 +38,7 @@ private RestRequester(TimeSpan requestTimeout, HttpClientHandler? clientHandler Client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("LeagueBroadcast", "2.0")); } - public static async Task GetAsync(string url, ICollection converters = null) + public static async Task GetAsync(string url) { try { @@ -53,20 +49,7 @@ private RestRequester(TimeSpan requestTimeout, HttpClientHandler? clientHandler return default; } var json = await response.Content.ReadAsStringAsync(); - - - var serializationOptions = new JsonSerializerOptions - { - }; - - if (converters != null) - { - foreach(var converter in converters) - { - serializationOptions.Converters.Add(converter); - } - } - return JsonSerializer.Deserialize(json, serializationOptions)!; + return JsonConvert.DeserializeObject< TResultType>(json)!; } catch (TaskCanceledException) { diff --git a/LeagueBroadcast.Update/GitHubReleaseInfo.cs b/LeagueBroadcast.Update/GitHubReleaseInfo.cs index 58b1677..9cc5071 100644 --- a/LeagueBroadcast.Update/GitHubReleaseInfo.cs +++ b/LeagueBroadcast.Update/GitHubReleaseInfo.cs @@ -1,16 +1,16 @@ -using System.Text.Json.Serialization; +using Newtonsoft.Json; namespace LeagueBroadcast.Update { public sealed class GitHubReleaseInfo { - [JsonPropertyName("tag_name")] - public string Version { get; set; } = ""; + [JsonProperty("tag_name")] + public string Version { get; set; } - [JsonPropertyName("html_url")] - public string Url { get; set; } = ""; + [JsonProperty("html_url")] + public string Url { get; set; } - [JsonPropertyName("assets")] - public GitHubReleaseAsset[] Assets { get; set; } = new GitHubReleaseAsset[0]; + [JsonProperty("assets")] + public GitHubReleaseAsset[] Assets { get; set; } } }