* Good start

* Misc

* Make ApiAuthenticationMiddleware use new json

* Remove first newtonsoft dependency

* Pull latest ASFB json enhancements

* Start reimplementing newtonsoft!

* One thing at a time

* Keep doing all kind of breaking changes which need to be tested later

* Add back ShouldSerialize() support

* Misc

* Eradicate remaining parts of newtonsoft

* WIP

* Workaround STJ stupidity in regards to derived types

STJ can't serialize derived type properties by default, so we'll use another approach in our serializable file function

* Make CI happy

* Bunch of further fixes

* Fix AddFreeLicense() after rewrite

* Add full support for JsonDisallowNullAttribute

* Optimize our json utilities even further

* Misc

* Add support for fields in disallow null

* Misc optimization

* Fix deserialization of GlobalCache in STD

* Fix non-public [JsonExtensionData]

* Fix IM missing method exception, correct db storage helpers

* Fix saving into generic databases

Thanks STJ

* Make Save() function abstract to force inheritors to implement it properly

* Correct ShouldSerializeAdditionalProperties to be a method

* Misc cleanup

* Code review

* Allow JSON comments in configs, among other

* Allow trailing commas in configs

Users very often add them accidentally, no reason to throw on them

* Fix confirmation ID

Probably needs further fixes, will need to check later

* Correct confirmations deserialization

* Use JsonNumberHandling

* Misc

* Misc

* [JsonDisallowNull] corrections

* Forbid [JsonDisallowNull] on non-nullable structs

* Not really but okay

* Add and use ToJson() helpers

* Misc

* Misc
This commit is contained in:
Łukasz Domeradzki
2024-02-21 03:09:36 +01:00
committed by GitHub
parent 3968130e15
commit 6b0bf0f9c1
114 changed files with 1714 additions and 1212 deletions

View File

@@ -27,6 +27,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using AngleSharp.Dom;
@@ -36,7 +37,6 @@ using Markdig;
using Markdig.Renderers;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using Newtonsoft.Json;
namespace ArchiSteamFarm.Web;
@@ -193,18 +193,6 @@ internal static class GitHub {
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
internal sealed class ReleaseResponse {
[JsonProperty("assets", Required = Required.Always)]
internal readonly ImmutableHashSet<Asset> Assets = ImmutableHashSet<Asset>.Empty;
[JsonProperty("prerelease", Required = Required.Always)]
internal readonly bool IsPreRelease;
[JsonProperty("published_at", Required = Required.Always)]
internal readonly DateTime PublishedAt;
[JsonProperty("tag_name", Required = Required.Always)]
internal readonly string Tag = "";
internal string? ChangelogHTML {
get {
if (BackingChangelogHTML != null) {
@@ -255,9 +243,6 @@ internal static class GitHub {
}
}
[JsonProperty("body", Required = Required.Always)]
private readonly string? MarkdownBody = "";
private MarkdownDocument? Changelog {
get {
if (BackingChangelog != null) {
@@ -274,22 +259,53 @@ internal static class GitHub {
}
}
[JsonInclude]
[JsonPropertyName("assets")]
[JsonRequired]
internal ImmutableHashSet<Asset> Assets { get; private init; } = ImmutableHashSet<Asset>.Empty;
[JsonInclude]
[JsonPropertyName("prerelease")]
[JsonRequired]
internal bool IsPreRelease { get; private init; }
[JsonInclude]
[JsonPropertyName("published_at")]
[JsonRequired]
internal DateTime PublishedAt { get; private init; }
[JsonInclude]
[JsonPropertyName("tag_name")]
[JsonRequired]
internal string Tag { get; private init; } = "";
private MarkdownDocument? BackingChangelog;
private string? BackingChangelogHTML;
private string? BackingChangelogPlainText;
[JsonInclude]
[JsonPropertyName("body")]
[JsonRequired]
private string? MarkdownBody { get; init; } = "";
[JsonConstructor]
private ReleaseResponse() { }
internal sealed class Asset {
[JsonProperty("browser_download_url", Required = Required.Always)]
internal readonly Uri? DownloadURL;
[JsonInclude]
[JsonPropertyName("browser_download_url")]
[JsonRequired]
internal Uri? DownloadURL { get; private init; }
[JsonProperty("name", Required = Required.Always)]
internal readonly string? Name;
[JsonInclude]
[JsonPropertyName("name")]
[JsonRequired]
internal string? Name { get; private init; }
[JsonProperty("size", Required = Required.Always)]
internal readonly uint Size;
[JsonInclude]
[JsonPropertyName("size")]
[JsonRequired]
internal uint Size { get; private init; }
[JsonConstructor]
private Asset() { }

View File

@@ -28,16 +28,16 @@ using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http.Json;
using System.Threading;
using System.Threading.Tasks;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Helpers.Json;
using ArchiSteamFarm.Localization;
using ArchiSteamFarm.NLog;
using ArchiSteamFarm.Storage;
using ArchiSteamFarm.Web.Responses;
using JetBrains.Annotations;
using Newtonsoft.Json;
namespace ArchiSteamFarm.Web;
@@ -323,17 +323,7 @@ public sealed class WebBrowser : IDisposable {
T? obj;
try {
using StreamReader streamReader = new(response.Content);
#pragma warning disable CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose
JsonTextReader jsonReader = new(streamReader);
#pragma warning restore CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose
await using (jsonReader.ConfigureAwait(false)) {
JsonSerializer serializer = new();
obj = serializer.Deserialize<T>(jsonReader);
}
obj = await response.Content.ToJsonObject<T>(cancellationToken).ConfigureAwait(false);
} catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) {
throw;
} catch (Exception e) {
@@ -606,17 +596,7 @@ public sealed class WebBrowser : IDisposable {
TResult? obj;
try {
using StreamReader streamReader = new(response.Content);
#pragma warning disable CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose
JsonTextReader jsonReader = new(streamReader);
#pragma warning restore CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose
await using (jsonReader.ConfigureAwait(false)) {
JsonSerializer serializer = new();
obj = serializer.Deserialize<TResult>(jsonReader);
}
obj = await response.Content.ToJsonObject<TResult>(cancellationToken).ConfigureAwait(false);
} catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) {
throw;
} catch (Exception e) {
@@ -762,7 +742,7 @@ public sealed class WebBrowser : IDisposable {
break;
default:
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
requestMessage.Content = JsonContent.Create(data, options: JsonUtilities.DefaultJsonSerialierOptions);
break;
}