Skip to content

Commit

Permalink
Make project not error on start
Browse files Browse the repository at this point in the history
The deserialization of the update information error'ed because the deserialization models mixed Newtonsoft.Json models with System.Text.Json models.
  • Loading branch information
FelixArbeithuber committed Apr 16, 2023
1 parent f4cf078 commit 6b6053b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
23 changes: 3 additions & 20 deletions LeagueBroadcast.Common/Http/RestRequester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -42,7 +38,7 @@ private RestRequester(TimeSpan requestTimeout, HttpClientHandler? clientHandler
Client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("LeagueBroadcast", "2.0"));
}

public static async Task<TResultType?> GetAsync<TResultType>(string url, ICollection<JsonConverter> converters = null)
public static async Task<TResultType?> GetAsync<TResultType>(string url)
{
try
{
Expand All @@ -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<TResultType>(json, serializationOptions)!;
return JsonConvert.DeserializeObject< TResultType>(json)!;
}
catch (TaskCanceledException)
{
Expand Down
14 changes: 7 additions & 7 deletions LeagueBroadcast.Update/GitHubReleaseInfo.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}

0 comments on commit 6b6053b

Please sign in to comment.