diff --git a/src/Camille.Core/Camille.Core.csproj b/src/Camille.Core/Camille.Core.csproj index 1e3e54ea..e1664b5a 100644 --- a/src/Camille.Core/Camille.Core.csproj +++ b/src/Camille.Core/Camille.Core.csproj @@ -1,7 +1,7 @@ - net45;net461;netstandard2.1;netcoreapp3.1;net6.0;net7.0 + netstandard2.1;net6.0;net7.0 Camille.Core Camille.Core Core utilities for Camille packages. diff --git a/src/Camille.Core/JsonHandler.cs b/src/Camille.Core/JsonHandler.cs index c2297a29..e6581553 100644 --- a/src/Camille.Core/JsonHandler.cs +++ b/src/Camille.Core/JsonHandler.cs @@ -2,58 +2,6 @@ namespace Camille.Core { -#if USE_NEWTONSOFT - public static class JsonHandler - { - /// Settings singleton. - private static readonly Newtonsoft.Json.JsonSerializerSettings jsonSerializerSettings = - new Newtonsoft.Json.JsonSerializerSettings() - { - NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, - Converters = new[] { new CustomIntConverter() }, - }; - - /// Int32 converter which is able to read integers with decimal points "123.0". - private class CustomIntConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(Type objectType) { return typeof(int) == objectType; } - - public override object ReadJson( - Newtonsoft.Json.JsonReader reader, Type objectType, - object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - if (Newtonsoft.Json.JsonToken.Float == reader.TokenType) - { - var doubleVal = serializer.Deserialize(reader); - var intVal = (int) doubleVal; - if (doubleVal == intVal) - return intVal; - throw new Newtonsoft.Json.JsonException($"Cannot parse number as int: {doubleVal}."); - } - return (int) serializer.Deserialize(reader); - } - - public override bool CanWrite { get { return false; } } - - public override void WriteJson( - Newtonsoft.Json.JsonWriter writer, object value, - Newtonsoft.Json.JsonSerializer serializer) - { - throw new NotImplementedException(); - } - } - - public static T Deserialize(string content) - { - return Newtonsoft.Json.JsonConvert.DeserializeObject(content, jsonSerializerSettings); - } - - public static string Serialize(T value) - { - return Newtonsoft.Json.JsonConvert.SerializeObject(value, jsonSerializerSettings); - } - } -#elif USE_SYSTEXTJSON public static class JsonHandler { /// Options singleton. @@ -96,7 +44,4 @@ public static string Serialize(T value) return System.Text.Json.JsonSerializer.Serialize(value, jsonOptions); } } -#else -#error One of USE_NEWTONSOFT or USE_SYSTEXTJSON must be set. -#endif } diff --git a/src/Camille.Enums/Camille.Enums.csproj b/src/Camille.Enums/Camille.Enums.csproj index 92b4163c..24fa37e1 100644 --- a/src/Camille.Enums/Camille.Enums.csproj +++ b/src/Camille.Enums/Camille.Enums.csproj @@ -1,7 +1,7 @@  - net45;net461;netstandard2.1;netcoreapp3.1;net6.0;net7.0 + netstandard2.1;net6.0;net7.0 Camille.Enums Camille.Enums Enums for League of Legends and other Riot Games games. diff --git a/src/Camille.Enums/gen/GameMode.cs.dt b/src/Camille.Enums/gen/GameMode.cs.dt index 5b4c59ba..f3c4ad9f 100644 --- a/src/Camille.Enums/gen/GameMode.cs.dt +++ b/src/Camille.Enums/gen/GameMode.cs.dt @@ -12,11 +12,7 @@ namespace Camille.Enums /// /// GameModes enum based on gameModes.json. /// -#if USE_NEWTONSOFT - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] -#elif USE_SYSTEXTJSON [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] -#endif public enum GameMode { {{ diff --git a/src/Camille.Enums/gen/GameType.cs.dt b/src/Camille.Enums/gen/GameType.cs.dt index f6795e02..09aeff52 100644 --- a/src/Camille.Enums/gen/GameType.cs.dt +++ b/src/Camille.Enums/gen/GameType.cs.dt @@ -12,11 +12,7 @@ namespace Camille.Enums /// /// GameTypes enum based on gameTypes.json. /// -#if USE_NEWTONSOFT - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] -#elif USE_SYSTEXTJSON [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] -#endif public enum GameType { {{ diff --git a/src/Camille.Enums/gen/QueueType.cs.dt b/src/Camille.Enums/gen/QueueType.cs.dt index 2fb4ce9a..198f8c47 100644 --- a/src/Camille.Enums/gen/QueueType.cs.dt +++ b/src/Camille.Enums/gen/QueueType.cs.dt @@ -10,11 +10,7 @@ using System.ComponentModel.DataAnnotations; namespace Camille.Enums { -#if USE_NEWTONSOFT - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] -#elif USE_SYSTEXTJSON [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] -#endif /// /// QueueType enum based on queueTypes.json. /// diff --git a/src/Camille.Enums/gen/Route.cs.dt b/src/Camille.Enums/gen/Route.cs.dt index ee7f429a..4973f5fd 100644 --- a/src/Camille.Enums/gen/Route.cs.dt +++ b/src/Camille.Enums/gen/Route.cs.dt @@ -13,11 +13,7 @@ namespace Camille.Enums /// /// Regional routes, used in tournament services, Legends of Runeterra (LoR), and some other endpoints. /// -#if USE_NEWTONSOFT - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] -#elif USE_SYSTEXTJSON [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] -#endif public enum RegionalRoute: byte { {{ @@ -46,11 +42,7 @@ namespace Camille.Enums /// /// Platform routes for League of Legends (LoL), Teanfight Tactics (TFT), and Legends of Runeterra (LoR). /// -#if USE_NEWTONSOFT - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] -#elif USE_SYSTEXTJSON [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] -#endif public enum PlatformRoute: byte { {{ @@ -79,11 +71,7 @@ namespace Camille.Enums /// /// Platform routes for Valorant. /// -#if USE_NEWTONSOFT - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] -#elif USE_SYSTEXTJSON [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] -#endif public enum ValPlatformRoute: byte { {{ @@ -113,11 +101,7 @@ namespace Camille.Enums /// Tournament regions for League of Legends (LoL) used in TournamentStubV4 and TournamentV4's /// RegisterProviderData method. /// -#if USE_NEWTONSOFT - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] -#elif USE_SYSTEXTJSON [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] -#endif public enum TournamentRegion: byte { {{ diff --git a/src/Camille.Enums/src/Division.cs b/src/Camille.Enums/src/Division.cs index 8e988684..9ed3d777 100644 --- a/src/Camille.Enums/src/Division.cs +++ b/src/Camille.Enums/src/Division.cs @@ -2,11 +2,7 @@ namespace Camille.Enums { -#if USE_NEWTONSOFT - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] -#elif USE_SYSTEXTJSON [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] -#endif public enum Division : byte { /// diff --git a/src/Camille.Enums/src/Locale.cs b/src/Camille.Enums/src/Locale.cs index db90274a..9fda7f24 100644 --- a/src/Camille.Enums/src/Locale.cs +++ b/src/Camille.Enums/src/Locale.cs @@ -1,10 +1,6 @@ namespace Camille.Enums { -#if USE_NEWTONSOFT - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] -#elif USE_SYSTEXTJSON [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] -#endif public enum Locale { en_US, diff --git a/src/Camille.Enums/src/Tier.cs b/src/Camille.Enums/src/Tier.cs index 4b1ad4aa..da8441d5 100644 --- a/src/Camille.Enums/src/Tier.cs +++ b/src/Camille.Enums/src/Tier.cs @@ -1,15 +1,9 @@ -using System; - -namespace Camille.Enums +namespace Camille.Enums { /// /// Contains tier names (CHALLENGER, MASTER, etc.) /// -#if USE_NEWTONSOFT - [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] -#elif USE_SYSTEXTJSON [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] -#endif public enum Tier : byte { CHALLENGER = 20, diff --git a/src/Camille.LolGame/Camille.LolGame.csproj b/src/Camille.LolGame/Camille.LolGame.csproj index 7bcf15e2..be4dc657 100644 --- a/src/Camille.LolGame/Camille.LolGame.csproj +++ b/src/Camille.LolGame/Camille.LolGame.csproj @@ -1,7 +1,7 @@  - net461;netstandard2.1;netcoreapp3.1;net6.0;net7.0 + netstandard2.1;net6.0;net7.0 Camille.LolGame Camille.LolGame League of Legends Live (In-Game) Client Data API library diff --git a/src/Camille.LolGame/src/LolGameErrorMessage.cs b/src/Camille.LolGame/src/LolGameErrorMessage.cs index dfed4cb7..e4828d0f 100644 --- a/src/Camille.LolGame/src/LolGameErrorMessage.cs +++ b/src/Camille.LolGame/src/LolGameErrorMessage.cs @@ -1,10 +1,4 @@ -#if USE_NEWTONSOFT -using JsonPropertyAttribute = Newtonsoft.Json.JsonPropertyAttribute; -#elif USE_SYSTEXTJSON -using JsonPropertyAttribute = System.Text.Json.Serialization.JsonPropertyNameAttribute; -#else -#error One of USE_NEWTONSOFT or USE_SYSTEXTJSON must be set. -#endif +using System.Text.Json.Serialization; namespace Camille.LolGame { @@ -14,20 +8,20 @@ public class LolGameErrorMessage public LolGameErrorMessage() { } #nullable restore - [JsonProperty("errorCode")] + [JsonPropertyName("errorCode")] public string ErrorCode { get; set; } - [JsonProperty("httpStatus")] + [JsonPropertyName("httpStatus")] public int HttpStatus { get; set; } - [JsonProperty("implementationDetails")] + [JsonPropertyName("implementationDetails")] public object ImplementationDetails { get; set; } /// /// If this is set to "Spectator mode doesn't currently support this feature" then you are calling a /// active-player endpoint while spectating. /// - [JsonProperty("message")] + [JsonPropertyName("message")] public string Message { get; set; } public override string ToString() diff --git a/src/Camille.RiotGames/Camille.RiotGames.csproj b/src/Camille.RiotGames/Camille.RiotGames.csproj index 2ba01893..9f770185 100644 --- a/src/Camille.RiotGames/Camille.RiotGames.csproj +++ b/src/Camille.RiotGames/Camille.RiotGames.csproj @@ -2,7 +2,7 @@ - net45;net461;netstandard2.1;netcoreapp3.1;net6.0;net7.0 + netstandard2.1;net6.0;net7.0 Camille.RiotGames Camille.RiotGames Riot Games API library. Fully rate limited, automatic retrying, thread-safe. Up-to-date nightlies. diff --git a/src/common.csproj.xml b/src/common.csproj.xml index 78acb1f0..0b600242 100644 --- a/src/common.csproj.xml +++ b/src/common.csproj.xml @@ -59,19 +59,11 @@ - - + + $(DefineConstants);INCLUDE_RIOTCERTIFICATEUTILS - - - $(DefineConstants);USE_NEWTONSOFT - - - - $(DefineConstants);USE_SYSTEXTJSON - - - - - - - - - - - + - + diff --git a/srcgen/dataClasses.dt b/srcgen/dataClasses.dt index e8c12feb..b806b6e3 100644 --- a/srcgen/dataClasses.dt +++ b/srcgen/dataClasses.dt @@ -10,19 +10,10 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json.Serialization; {{= it.usings.join('\r\n') }} -#if USE_NEWTONSOFT -using JsonPropertyAttribute = Newtonsoft.Json.JsonPropertyAttribute; -using JsonExtensionDataAttribute = Newtonsoft.Json.JsonExtensionDataAttribute; -#elif USE_SYSTEXTJSON -using JsonPropertyAttribute = System.Text.Json.Serialization.JsonPropertyNameAttribute; -using JsonExtensionDataAttribute = System.Text.Json.Serialization.JsonExtensionDataAttribute; -#else -#error One of USE_NEWTONSOFT or USE_SYSTEXTJSON must be set. -#endif - // ReSharper disable InconsistentNaming {{/* DTOs */}} diff --git a/srcgen/dotUtils.js b/srcgen/dotUtils.js index baa5fc33..cc6e16e4 100644 --- a/srcgen/dotUtils.js +++ b/srcgen/dotUtils.js @@ -106,7 +106,7 @@ function replaceEnumCasts(input) { } function formatJsonProperty(name) { - return `[JsonProperty("${name}")]`; + return `[JsonPropertyName("${name}")]`; } function formatQueryParamStringify(expr, prop) {