mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2025-12-23 09:48:37 +00:00
Apply guid json converter only where we need it
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ArchiSteamFarm.Helpers.Json;
|
||||
|
||||
@@ -32,9 +33,8 @@ namespace ArchiSteamFarm.Helpers.Json;
|
||||
/// TODO: This class exists purely because STJ can't deserialize Guid in other formats than default, at least for now
|
||||
/// https://github.com/dotnet/runtime/issues/30692
|
||||
/// </summary>
|
||||
internal sealed class GuidJsonConverter : JsonConverter<Guid> {
|
||||
internal static readonly GuidJsonConverter Shared = new();
|
||||
|
||||
[PublicAPI]
|
||||
public sealed class GuidJsonConverter : JsonConverter<Guid> {
|
||||
public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
|
||||
if (reader.TryGetGuid(out Guid result)) {
|
||||
// Great, we can work with it
|
||||
|
||||
@@ -113,7 +113,6 @@ public static class JsonUtilities {
|
||||
private static JsonSerializerOptions CreateDefaultJsonSerializerOptions(bool writeIndented = false) =>
|
||||
new() {
|
||||
AllowTrailingCommas = true,
|
||||
Converters = { GuidJsonConverter.Shared },
|
||||
PropertyNamingPolicy = null,
|
||||
ReadCommentHandling = JsonCommentHandling.Skip,
|
||||
TypeInfoResolver = new DefaultJsonTypeInfoResolver { Modifiers = { ApplyCustomModifiers } },
|
||||
|
||||
@@ -31,7 +31,6 @@ using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using ArchiSteamFarm.Core;
|
||||
using ArchiSteamFarm.Helpers.Json;
|
||||
@@ -388,10 +387,6 @@ internal static class ArchiKestrel {
|
||||
static options => {
|
||||
JsonSerializerOptions jsonSerializerOptions = Debugging.IsUserDebugging ? JsonUtilities.IndentedJsonSerialierOptions : JsonUtilities.DefaultJsonSerialierOptions;
|
||||
|
||||
foreach (JsonConverter converter in jsonSerializerOptions.Converters) {
|
||||
options.JsonSerializerOptions.Converters.Add(converter);
|
||||
}
|
||||
|
||||
options.JsonSerializerOptions.PropertyNamingPolicy = jsonSerializerOptions.PropertyNamingPolicy;
|
||||
options.JsonSerializerOptions.TypeInfoResolver = jsonSerializerOptions.TypeInfoResolver;
|
||||
options.JsonSerializerOptions.WriteIndented = jsonSerializerOptions.WriteIndented;
|
||||
|
||||
@@ -64,17 +64,17 @@ public sealed class InventoryDescription {
|
||||
private init => Body.classid = value;
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(BooleanNumberConverter))]
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("commodity")]
|
||||
[JsonConverter(typeof(BooleanNumberConverter))]
|
||||
public bool Commodity {
|
||||
get => Body.commodity;
|
||||
private init => Body.commodity = value;
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(BooleanNumberConverter))]
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("currency")]
|
||||
[JsonConverter(typeof(BooleanNumberConverter))]
|
||||
public bool Currency {
|
||||
get => Body.currency;
|
||||
private init => Body.currency = value;
|
||||
@@ -127,10 +127,10 @@ public sealed class InventoryDescription {
|
||||
private init => Body.instanceid = value;
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(BooleanNumberConverter))]
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("marketable")]
|
||||
[JsonRequired]
|
||||
[JsonConverter(typeof(BooleanNumberConverter))]
|
||||
public bool Marketable {
|
||||
get => Body.marketable;
|
||||
private init => Body.marketable = value;
|
||||
@@ -301,10 +301,10 @@ public sealed class InventoryDescription {
|
||||
}
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(BooleanNumberConverter))]
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("tradable")]
|
||||
[JsonRequired]
|
||||
[JsonConverter(typeof(BooleanNumberConverter))]
|
||||
internal bool Tradable {
|
||||
get => Body.tradable;
|
||||
private init => Body.tradable = value;
|
||||
|
||||
@@ -51,9 +51,9 @@ internal sealed class InventoryResponse : OptionalResultResponse {
|
||||
[JsonPropertyName("last_assetid")]
|
||||
internal ulong LastAssetID { get; private init; }
|
||||
|
||||
[JsonConverter(typeof(BooleanNumberConverter))]
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("more_items")]
|
||||
[JsonConverter(typeof(BooleanNumberConverter))]
|
||||
internal bool MoreItems { get; private init; }
|
||||
|
||||
[JsonInclude]
|
||||
|
||||
@@ -263,6 +263,7 @@ public sealed class GlobalConfig {
|
||||
[JsonInclude]
|
||||
public ArchiCryptoHelper.EHashingMethod IPCPasswordFormat { get; private init; } = DefaultIPCPasswordFormat;
|
||||
|
||||
[JsonConverter(typeof(GuidJsonConverter))]
|
||||
[JsonInclude]
|
||||
public Guid? LicenseID { get; private init; } = DefaultLicenseID;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user