Fully remove the dependency on Newtonsoft.Json

This commit is contained in:
Daan Boerlage 2021-11-01 01:27:04 +01:00
parent cf0cd743b8
commit 8c2eabfd21
Signed by: daan
GPG key ID: FCE070E1E4956606
18 changed files with 92 additions and 22 deletions

View file

@ -46,9 +46,9 @@ namespace Geekbot.Bot.Commands.Integrations.LolMmr
var sb = new StringBuilder();
sb.AppendLine($"**MMR for {summonerName}**");
sb.AppendLine($"Normal: {data.Normal.Avg}");
sb.AppendLine($"Ranked: {data.Ranked.Avg}");
sb.AppendLine($"ARAM: {data.ARAM.Avg}");
sb.AppendLine($"Normal: {data.Normal?.Avg ?? 0}");
sb.AppendLine($"Ranked: {data.Ranked?.Avg ?? 0}");
sb.AppendLine($"ARAM: {data.ARAM?.Avg ?? 0}");
await Context.Channel.SendMessageAsync(sb.ToString());
}

View file

@ -1,9 +1,16 @@
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Integrations.LolMmr
{
public class LolMmrDto
{
[JsonPropertyName("ranked")]
public LolMrrInfoDto Ranked { get; set; }
[JsonPropertyName("normal")]
public LolMrrInfoDto Normal { get; set; }
[JsonPropertyName("aram")]
public LolMrrInfoDto ARAM { get; set; }
}
}

View file

@ -5,7 +5,6 @@ namespace Geekbot.Bot.Commands.Integrations.LolMmr
public class LolMrrInfoDto
{
[JsonPropertyName("avg")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public decimal Avg { get; set; } = 0;
public decimal? Avg { get; set; }
}
}

View file

@ -1,12 +1,26 @@
namespace Geekbot.Bot.Commands.Integrations.UbranDictionary
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Integrations.UbranDictionary
{
internal class UrbanListItemDto
{
[JsonPropertyName("definition")]
public string Definition { get; set; }
[JsonPropertyName("permalink")]
public string Permalink { get; set; }
public string ThumbsUp { get; set; }
[JsonPropertyName("thumbs_up")]
public int ThumbsUp { get; set; }
[JsonPropertyName("word")]
public string Word { get; set; }
[JsonPropertyName("example")]
public string Example { get; set; }
public string ThumbsDown { get; set; }
[JsonPropertyName("thumbs_down")]
public int ThumbsDown { get; set; }
}
}

View file

@ -1,10 +1,14 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Integrations.UbranDictionary
{
internal class UrbanResponseDto
{
[JsonPropertyName("tags")]
public string[] Tags { get; set; }
[JsonPropertyName("list")]
public List<UrbanListItemDto> List { get; set; }
}
}

View file

@ -45,8 +45,8 @@ namespace Geekbot.Bot.Commands.Integrations.UbranDictionary
if (!string.IsNullOrEmpty(definition.Definition)) eb.Description = ShortenIfToLong(definition.Definition, 1800);
if (!string.IsNullOrEmpty(definition.Example)) eb.AddField("Example", ShortenIfToLong(definition.Example, 1024));
if (!string.IsNullOrEmpty(definition.ThumbsUp)) eb.AddInlineField("Upvotes", definition.ThumbsUp);
if (!string.IsNullOrEmpty(definition.ThumbsDown)) eb.AddInlineField("Downvotes", definition.ThumbsDown);
if (definition.ThumbsUp != 0) eb.AddInlineField("Upvotes", definition.ThumbsUp);
if (definition.ThumbsDown != 0) eb.AddInlineField("Downvotes", definition.ThumbsDown);
if (definitions.Tags?.Length > 0) eb.AddField("Tags", string.Join(", ", definitions.Tags));
await ReplyAsync("", false, eb.Build());

View file

@ -1,7 +1,10 @@
namespace Geekbot.Bot.Commands.Randomness.Cat
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Randomness.Cat
{
internal class CatResponseDto
{
[JsonPropertyName("file")]
public string File { get; set; }
}
}

View file

@ -1,7 +1,10 @@
namespace Geekbot.Bot.Commands.Randomness.Chuck
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Randomness.Chuck
{
internal class ChuckNorrisJokeResponseDto
{
[JsonPropertyName("value")]
public string Value { get; set; }
}
}

View file

@ -1,7 +1,10 @@
namespace Geekbot.Bot.Commands.Randomness.Dad
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Randomness.Dad
{
internal class DadJokeResponseDto
{
[JsonPropertyName("joke")]
public string Joke { get; set; }
}
}

View file

@ -1,7 +1,10 @@
namespace Geekbot.Bot.Commands.Randomness.Dog
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Randomness.Dog
{
internal class DogResponseDto
{
[JsonPropertyName("url")]
public string Url { get; set; }
}
}

View file

@ -1,11 +1,22 @@
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Randomness.Greetings
{
public class GreetingBaseDto
{
[JsonPropertyName("language")]
public string Language { get; set; }
[JsonPropertyName("languageNative")]
public string LanguageNative { get; set; }
[JsonPropertyName("languageCode")]
public string LanguageCode { get; set; }
[JsonPropertyName("script")]
public string Script { get; set; }
[JsonPropertyName("primary")]
public GreetingDto Primary { get; set; }
}
}

View file

@ -1,10 +1,19 @@
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Randomness.Greetings
{
public class GreetingDto
{
[JsonPropertyName("text")]
public string Text { get; set; }
[JsonPropertyName("dialect")]
public string Dialect { get; set; }
[JsonPropertyName("romanization")]
public string Romanization { get; set; }
[JsonPropertyName("use")]
public string[] Use { get; set; }
}
}

View file

@ -1,8 +1,10 @@
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Randomness.Kanye
{
public class KanyeResponseDto
{
public string Id { get; set; }
[JsonPropertyName("quote")]
public string Quote { get; set; }
}
}

View file

@ -1,11 +1,17 @@
using System;
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Utils.Changelog
{
public class CommitAuthorDto
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("email")]
public string Email { get; set; }
[JsonPropertyName("date")]
public DateTimeOffset Date { get; set; }
}
}

View file

@ -1,7 +1,10 @@
namespace Geekbot.Bot.Commands.Utils.Changelog
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Utils.Changelog
{
public class CommitDto
{
[JsonPropertyName("commit")]
public CommitInfoDto Commit { get; set; }
}
}

View file

@ -1,8 +1,13 @@
namespace Geekbot.Bot.Commands.Utils.Changelog
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Utils.Changelog
{
public class CommitInfoDto
{
[JsonPropertyName("author")]
public CommitAuthorDto Author { get; set; }
[JsonPropertyName("message")]
public string Message { get; set; }
}
}

View file

@ -28,7 +28,6 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0-preview.2.21154.6" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0-preview.2.21154.6" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0-preview.2.21154.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NLog" Version="4.7.2" />
<PackageReference Include="NLog.Config" Version="4.7.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0-preview2" />

View file

@ -5,7 +5,6 @@ using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Geekbot.Core
{
@ -39,7 +38,7 @@ namespace Geekbot.Core
httpClient.Dispose();
}
return JsonConvert.DeserializeObject<TResponse>(stringResponse);
return JsonSerializer.Deserialize<TResponse>(stringResponse);
}
public static async Task<TResponse> Post<TResponse>(Uri location, object data, HttpClient httpClient = null, bool disposeClient = true)
@ -48,7 +47,7 @@ namespace Geekbot.Core
httpClient.BaseAddress = location;
var content = new StringContent(
System.Text.Json.JsonSerializer.Serialize(data, new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }),
JsonSerializer.Serialize(data, new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }),
Encoding.UTF8,
"application/json"
);
@ -61,7 +60,7 @@ namespace Geekbot.Core
httpClient.Dispose();
}
return JsonConvert.DeserializeObject<TResponse>(stringResponse);
return JsonSerializer.Deserialize<TResponse>(stringResponse);
}
public static async Task Post(Uri location, object data, HttpClient httpClient = null, bool disposeClient = true)