Get rid of Newtonsoft.Json everywhere but the HTTP abstractions

This commit is contained in:
Daan Boerlage 2021-11-01 01:04:20 +01:00
parent 7b06965f14
commit cf0cd743b8
Signed by: daan
GPG key ID: FCE070E1E4956606
15 changed files with 105 additions and 48 deletions

View file

@ -27,7 +27,6 @@
<PackageReference Include="HtmlAgilityPack" Version="1.11.36" />
<PackageReference Include="JikanDotNet" Version="1.6.0" />
<PackageReference Include="MtgApiManager.Lib" Version="1.2.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="PokeApi.NET" Version="1.1.2" />
<PackageReference Include="Sentry" Version="3.9.2" />
</ItemGroup>

View file

@ -1,10 +1,11 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Integrations.LolMmr
{
public class LolMrrInfoDto
{
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("avg")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public decimal Avg { get; set; } = 0;
}
}

View file

@ -1,19 +1,19 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Utils.Corona
{
public record CoronaApiCountryResponseDto
{
[JsonProperty("country")]
[JsonPropertyName("country")]
public string Country { get; init; }
[JsonProperty("cases")]
[JsonPropertyName("cases")]
public decimal Cases { get; init; }
[JsonProperty("deaths")]
[JsonPropertyName("deaths")]
public decimal Deaths { get; init; }
[JsonProperty("recovered")]
[JsonPropertyName("recovered")]
public decimal Recovered { get; init; }
}
}

View file

@ -1,14 +1,26 @@
using System;
using System.Text.Json.Serialization;
namespace Geekbot.Core.WikipediaClient.Page
{
public class PageApiUrls
{
[JsonPropertyName("summary")]
public Uri Summary { get; set; }
[JsonPropertyName("metadata")]
public Uri Metadata { get; set; }
[JsonPropertyName("references")]
public Uri References { get; set; }
[JsonPropertyName("media")]
public Uri Media { get; set; }
[JsonPropertyName("edit_html")]
public Uri EditHtml { get; set; }
[JsonPropertyName("talk_page_html")]
public Uri TalkPageHtml { get; set; }
}
}

View file

@ -1,8 +1,13 @@
namespace Geekbot.Core.WikipediaClient.Page
using System.Text.Json.Serialization;
namespace Geekbot.Core.WikipediaClient.Page
{
public class PageContentUrlCollection
{
[JsonPropertyName("desktop")]
public PageContentUrls Desktop { get; set; }
[JsonPropertyName("mobile")]
public PageContentUrls Mobile { get; set; }
}
}

View file

@ -1,12 +1,20 @@
using System;
using System.Text.Json.Serialization;
namespace Geekbot.Core.WikipediaClient.Page
{
public class PageContentUrls
{
[JsonPropertyName("page")]
public Uri Page { get; set; }
[JsonPropertyName("revisions")]
public Uri Revisions { get; set; }
[JsonPropertyName("edit")]
public Uri Edit { get; set; }
[JsonPropertyName("talk")]
public Uri Talk { get; set; }
}
}

View file

@ -1,8 +1,13 @@
namespace Geekbot.Core.WikipediaClient.Page
using System.Text.Json.Serialization;
namespace Geekbot.Core.WikipediaClient.Page
{
public class PageCoordinates
{
[JsonPropertyName("lat")]
public float Lat { get; set; }
[JsonPropertyName("lon")]
public float Lon { get; set; }
}
}

View file

@ -1,11 +1,17 @@
using System;
using System.Text.Json.Serialization;
namespace Geekbot.Core.WikipediaClient.Page
{
public class PageImage
{
[JsonPropertyName("source")]
public Uri Source { get; set; }
[JsonPropertyName("width")]
public int Width { get; set; }
[JsonPropertyName("height")]
public int Height { get; set; }
}

View file

@ -1,8 +1,13 @@
namespace Geekbot.Core.WikipediaClient.Page
using System.Text.Json.Serialization;
namespace Geekbot.Core.WikipediaClient.Page
{
public class PageNamespace
{
[JsonPropertyName("id")]
public ulong Id { get; set; }
[JsonPropertyName("text")]
public string Text { get; set; }
}
}

View file

@ -1,67 +1,65 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Text.Json.Serialization;
namespace Geekbot.Core.WikipediaClient.Page
{
public class PagePreview
{
[JsonProperty("type")]
[JsonConverter(typeof(StringEnumConverter))]
[JsonPropertyName("type")]
public PageTypes Type { get; set; }
[JsonProperty("title")]
[JsonPropertyName("title")]
public string Title { get; set; }
[JsonProperty("displaytitle")]
[JsonPropertyName("displaytitle")]
public string Displaytitle { get; set; }
[JsonProperty("namespace")]
[JsonPropertyName("namespace")]
public PageNamespace Namespace { get; set; }
[JsonProperty("titles")]
[JsonPropertyName("titles")]
public PageTitles Titles { get; set; }
[JsonProperty("pageid")]
[JsonPropertyName("pageid")]
public ulong Pageid { get; set; }
[JsonProperty("thumbnail")]
[JsonPropertyName("thumbnail")]
public PageImage Thumbnail { get; set; }
[JsonProperty("originalimage")]
[JsonPropertyName("originalimage")]
public PageImage Originalimage { get; set; }
[JsonProperty("lang")]
[JsonPropertyName("lang")]
public string Lang { get; set; }
[JsonProperty("dir")]
[JsonPropertyName("dir")]
public string Dir { get; set; }
[JsonProperty("revision")]
public ulong Revision { get; set; }
[JsonPropertyName("revision")]
public string Revision { get; set; }
[JsonProperty("tid")]
[JsonPropertyName("tid")]
public string Tid { get; set; }
[JsonProperty("timestamp")]
[JsonPropertyName("timestamp")]
public DateTimeOffset Timestamp { get; set; }
[JsonProperty("description")]
[JsonPropertyName("description")]
public string Description { get; set; }
[JsonProperty("coordinates")]
[JsonPropertyName("coordinates")]
public PageCoordinates Coordinates { get; set; }
[JsonProperty("content_urls")]
[JsonPropertyName("content_urls")]
public PageContentUrlCollection ContentUrls { get; set; }
[JsonProperty("api_urls")]
[JsonPropertyName("api_urls")]
public PageApiUrls ApiUrls { get; set; }
[JsonProperty("extract")]
[JsonPropertyName("extract")]
public string Extract { get; set; }
[JsonProperty("extract_html")]
[JsonPropertyName("extract_html")]
public string ExtractHtml { get; set; }
}
}

View file

@ -1,10 +1,16 @@
namespace Geekbot.Core.WikipediaClient.Page
using System.Text.Json.Serialization;
namespace Geekbot.Core.WikipediaClient.Page
{
public class PageTitles
{
[JsonPropertyName("Canonical")]
public string Canonical { get; set; }
public string Normalized { get; set; }
public string Display { get; set; }
[JsonPropertyName("Normalized")]
public string Normalized { get; set; }
[JsonPropertyName("Display")]
public string Display { get; set; }
}
}

View file

@ -1,7 +1,9 @@
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
namespace Geekbot.Core.WikipediaClient.Page
{
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum PageTypes
{
[EnumMember(Value = "standard")]

View file

@ -1,7 +1,7 @@
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Geekbot.Core.WikipediaClient.Page;
using Newtonsoft.Json;
namespace Geekbot.Core.WikipediaClient
{
@ -19,7 +19,7 @@ namespace Geekbot.Core.WikipediaClient
response.EnsureSuccessStatusCode();
var stringResponse = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<PagePreview>(stringResponse);
return JsonSerializer.Deserialize<PagePreview>(stringResponse);
}
}
}

View file

@ -2,11 +2,10 @@ using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;
using Discord.WebSocket;
using Geekbot.Core.GlobalSettings;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace Geekbot.Web.Controllers.Callback
{
@ -45,8 +44,8 @@ namespace Geekbot.Web.Controllers.Callback
result.EnsureSuccessStatusCode();
var stringResponse = await result.Content.ReadAsStringAsync();
var responseData = JsonConvert.DeserializeObject<CallbackTokenResponseDto>(stringResponse);
token = responseData.access_token;
var responseData = JsonSerializer.Deserialize<CallbackTokenResponseDto>(stringResponse);
token = responseData.AccessToken;
}
return new RedirectResult($"https://geekbot.pizzaandcoffee.rocks/login?token={token}", false);

View file

@ -1,11 +1,22 @@
using System.Text.Json.Serialization;
namespace Geekbot.Web.Controllers.Callback
{
public class CallbackTokenResponseDto
{
public string access_token { get; set; }
public string token_type { get; set; }
public int expires_in { get; set; }
public string refresh_token { get; set; }
public string scope { get; set; }
[JsonPropertyName("access_token")]
public string AccessToken { get; set; }
[JsonPropertyName("token_type")]
public string TokenType { get; set; }
[JsonPropertyName("expires_in")]
public int ExpiresIn { get; set; }
[JsonPropertyName("refresh_token")]
public string RefreshToken { get; set; }
[JsonPropertyName("scope")]
public string Scope { get; set; }
}
}