diff --git a/API/OCM.Net/OCM.API.Client/OCM.API.Client.csproj b/API/OCM.Net/OCM.API.Client/OCM.API.Client.csproj index fddfda9f..2ad6a7f1 100644 --- a/API/OCM.Net/OCM.API.Client/OCM.API.Client.csproj +++ b/API/OCM.Net/OCM.API.Client/OCM.API.Client.csproj @@ -1,7 +1,7 @@  8.0.30703 - net6.0 + net8.0 ..\..\..\ OCM.API.Client OCM.API.Client @@ -43,7 +43,7 @@ - + diff --git a/API/OCM.Net/OCM.API.Core/OCM.API.Core.csproj b/API/OCM.Net/OCM.API.Core/OCM.API.Core.csproj index 1d822b0b..8281d41d 100644 --- a/API/OCM.Net/OCM.API.Core/OCM.API.Core.csproj +++ b/API/OCM.Net/OCM.API.Core/OCM.API.Core.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Library @@ -57,18 +57,18 @@ - - + + - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/API/OCM.Net/OCM.API.Model/OCM.API.Common.Model.csproj b/API/OCM.Net/OCM.API.Model/OCM.API.Common.Model.csproj index 252da465..c267d795 100644 --- a/API/OCM.Net/OCM.API.Model/OCM.API.Common.Model.csproj +++ b/API/OCM.Net/OCM.API.Model/OCM.API.Common.Model.csproj @@ -2,7 +2,7 @@ 8.0.30703 {F330ECA1-D079-4EE0-AEB4-30A3FD67FE03} - net6.0 + net8.0 ..\..\..\ OCM.API.Model http://openchargemap.org diff --git a/API/OCM.Net/OCM.API.Web/Compatibility/CompatibilityAPIHandler.cs b/API/OCM.Net/OCM.API.Web/Compatibility/CompatibilityAPIHandler.cs index 4b572c19..aa519f77 100644 --- a/API/OCM.Net/OCM.API.Web/Compatibility/CompatibilityAPIHandler.cs +++ b/API/OCM.Net/OCM.API.Web/Compatibility/CompatibilityAPIHandler.cs @@ -402,7 +402,7 @@ private async Task OutputSubmissionReceivedMessage(HttpContext context, string m /// private async Task PerformOutput(HttpContext context) { - //decide correct reponse type + //decide correct response type IOutputProvider outputProvider = null; var filter = new APIRequestParams(); diff --git a/API/OCM.Net/OCM.API.Web/Compatibility/OutputProviders/JSONOutputProvider.cs b/API/OCM.Net/OCM.API.Web/Compatibility/OutputProviders/JSONOutputProvider.cs index 2fdbeab1..0ab2dbbd 100644 --- a/API/OCM.Net/OCM.API.Web/Compatibility/OutputProviders/JSONOutputProvider.cs +++ b/API/OCM.Net/OCM.API.Web/Compatibility/OutputProviders/JSONOutputProvider.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.Serialization.Json; +using System.Text.Json; using System.Threading.Tasks; namespace OCM.API.OutputProviders @@ -15,12 +16,12 @@ public class POINonComputedContractResolver : DefaultContractResolver { public static readonly POINonComputedContractResolver Instance = new POINonComputedContractResolver(); - protected override JsonProperty CreateProperty(System.Reflection.MemberInfo member, MemberSerialization memberSerialization) + protected override Newtonsoft.Json.Serialization.JsonProperty CreateProperty(System.Reflection.MemberInfo member, MemberSerialization memberSerialization) { - JsonProperty property = base.CreateProperty(member, memberSerialization); + var property = base.CreateProperty(member, memberSerialization); // don't seralize computed properties - if (property.DeclaringType == typeof(ChargePoint) && + if (property.DeclaringType == typeof(ChargePoint) && property.PropertyName == "IsRecentlyVerified" || property.PropertyName == "DataQualityLevel" @@ -35,13 +36,15 @@ protected override JsonProperty CreateProperty(System.Reflection.MemberInfo memb public class JSONOutputProvider : OutputProviderBase, IOutputProvider { + private bool _useSystemTextJson = true; + public JSONOutputProvider() { ContentType = "application/json"; } - public string PerformSerialisationToString(object graph, JsonSerializerSettings serializerSettings) + public async Task PerformSerialisationToString(object graph, JsonSerializerSettings serializerSettings) { if (serializerSettings != null) { @@ -62,7 +65,7 @@ public async Task PerformSerialisationV2(System.IO.Stream outputStream, object g public void PerformBinarySerialisation(System.IO.Stream outputStream, object graph, string jsCallbackName) { //MemoryStream ms = new MemoryStream(); - JsonSerializer serializer = new JsonSerializer(); + Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer(); // serialize product to BSON BsonWriter writer = new BsonWriter(outputStream); @@ -84,7 +87,7 @@ public async Task PerformSerialisationV2(System.IO.Stream outputStream, object g await s.WriteAsync(jsCallbackName + "("); } - string json = PerformSerialisationToString(graph, serializerSettings); + string json = await PerformSerialisationToString(graph, serializerSettings); await s.WriteAsync(json); if (jsCallbackName != null) @@ -95,6 +98,26 @@ public async Task PerformSerialisationV2(System.IO.Stream outputStream, object g await s.FlushAsync(); } + public async Task PerformSerialisationV3(System.IO.Stream outputStream, object graph, string jsCallbackName, JsonSerializerOptions serializerSettings) + { + System.IO.StreamWriter s = new StreamWriter(outputStream); + + if (jsCallbackName != null) + { + await s.WriteAsync(jsCallbackName + "("); + } + + await System.Text.Json.JsonSerializer.SerializeAsync(outputStream, graph, serializerSettings); + //await s.WriteAsync(json); + + if (jsCallbackName != null) + { + await s.WriteAsync(")"); + } + + await s.FlushAsync(); + } + /// /// Serialise using DataContractSerializer /// @@ -136,7 +159,15 @@ public async Task GetOutput(HttpContext context, System.IO.Stream outputStream, { if (settings.APIVersion >= 2) { - await PerformSerialisationV2(outputStream, dataList, settings.Callback, GetSerializerSettings(settings)); + if (_useSystemTextJson) + { + // use System.Text.Json as optimisation instead of Newtonsoft + await PerformSerialisationV3(outputStream, dataList, settings.Callback, GetSerializerOptions(settings)); + } + else + { + await PerformSerialisationV2(outputStream, dataList, settings.Callback, GetSerializerSettings(settings)); + } } else { @@ -149,7 +180,15 @@ public async Task GetOutput(HttpContext context, Stream outputStream, Common.Mod { if (settings.APIVersion >= 2) { - await PerformSerialisationV2(outputStream, data, settings.Callback, GetSerializerSettings(settings)); + if (_useSystemTextJson) + { + await PerformSerialisationV3(outputStream, data, settings.Callback, GetSerializerOptions(settings)); + } + else + { + await PerformSerialisationV2(outputStream, data, settings.Callback, GetSerializerSettings(settings)); + } + } else { @@ -160,7 +199,14 @@ public async Task GetOutput(HttpContext context, Stream outputStream, Common.Mod public async Task GetOutput(HttpContext context, Stream outputStream, Object data, Common.APIRequestParams settings) { - await PerformSerialisationV2(outputStream, data, settings.Callback, GetSerializerSettings(settings)); + if (_useSystemTextJson) + { + await PerformSerialisationV3(outputStream, data, settings.Callback, GetSerializerOptions(settings)); + } + else + { + await PerformSerialisationV2(outputStream, data, settings.Callback, GetSerializerSettings(settings)); + } } private JsonSerializerSettings GetSerializerSettings(Common.APIRequestParams settings) @@ -190,5 +236,33 @@ private JsonSerializerSettings GetSerializerSettings(Common.APIRequestParams set return jsonSettings; } + + private System.Text.Json.JsonSerializerOptions GetSerializerOptions(Common.APIRequestParams settings) + { + JsonSerializerOptions jsonSettings = new JsonSerializerOptions(); + + if (!settings.IsVerboseOutput) + { + jsonSettings.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull; + } + + jsonSettings.WriteIndented = true; + + if (settings.IsCompactOutput) + { + jsonSettings.WriteIndented = false; + } + if (settings.IsCamelCaseOutput) + { + jsonSettings.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; + } + + if (settings.ExcludeComputedProperties) + { + // jsonSettings.ContractResolver = new POINonComputedContractResolver(); + } + + return jsonSettings; + } } } \ No newline at end of file diff --git a/API/OCM.Net/OCM.API.Web/OCM.API.Web.csproj b/API/OCM.Net/OCM.API.Web/OCM.API.Web.csproj index 830dda3e..d4ff9761 100644 --- a/API/OCM.Net/OCM.API.Web/OCM.API.Web.csproj +++ b/API/OCM.Net/OCM.API.Web/OCM.API.Web.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 407b1e1a-5108-48b6-bb48-4990a0804269 diff --git a/API/OCM.Net/OCM.API.Worker/OCM.API.Worker.csproj b/API/OCM.Net/OCM.API.Worker/OCM.API.Worker.csproj index d6e87d45..3dae4889 100644 --- a/API/OCM.Net/OCM.API.Worker/OCM.API.Worker.csproj +++ b/API/OCM.Net/OCM.API.Worker/OCM.API.Worker.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable 22dd266a-d0c7-4802-a609-26bd7bda47e9 Linux @@ -9,7 +9,7 @@ - + diff --git a/Import/OCM.Import.Analysis/OCM.Import.Analysis.csproj b/Import/OCM.Import.Analysis/OCM.Import.Analysis.csproj index 034c5032..7312a6b7 100644 --- a/Import/OCM.Import.Analysis/OCM.Import.Analysis.csproj +++ b/Import/OCM.Import.Analysis/OCM.Import.Analysis.csproj @@ -1,7 +1,7 @@  {FBD1BB19-0912-4A8C-BE95-197CCDC27CF3} - net6.0 + net8.0 OCM.Import.Analysis OCM.Import.Analysis Copyright © 2015 @@ -28,7 +28,7 @@ - + diff --git a/Import/OCM.Import.Common/OCM.Import.Common.csproj b/Import/OCM.Import.Common/OCM.Import.Common.csproj index 50b3ab9d..bf631378 100644 --- a/Import/OCM.Import.Common/OCM.Import.Common.csproj +++ b/Import/OCM.Import.Common/OCM.Import.Common.csproj @@ -2,7 +2,7 @@ 8.0.30703 OCM.Import - net6.0 + net8.0 ..\..\ OCM.Import.Common http://openchargemap.org @@ -41,11 +41,11 @@ - + - + diff --git a/Import/OCM.Import.Manager.Console/OCM.Import.Manager.Console.csproj b/Import/OCM.Import.Manager.Console/OCM.Import.Manager.Console.csproj index c7bc4e8c..865675b2 100644 --- a/Import/OCM.Import.Manager.Console/OCM.Import.Manager.Console.csproj +++ b/Import/OCM.Import.Manager.Console/OCM.Import.Manager.Console.csproj @@ -1,7 +1,7 @@  Exe - net7.0-windows + net8.0-windows7.0 true true @@ -18,7 +18,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Import/OCM.Import.Manager.UI/OCM.Import.Manager.UI.csproj b/Import/OCM.Import.Manager.UI/OCM.Import.Manager.UI.csproj index 68d8bf99..a28a39e9 100644 --- a/Import/OCM.Import.Manager.UI/OCM.Import.Manager.UI.csproj +++ b/Import/OCM.Import.Manager.UI/OCM.Import.Manager.UI.csproj @@ -1,7 +1,7 @@  WinExe - net7.0-windows + net8.0-windows7.0 true true @@ -25,10 +25,10 @@ - - - - + + + + diff --git a/Import/OCM.Import.Worker/OCM.Import.Worker.csproj b/Import/OCM.Import.Worker/OCM.Import.Worker.csproj index dbb017b6..e375d46b 100644 --- a/Import/OCM.Import.Worker/OCM.Import.Worker.csproj +++ b/Import/OCM.Import.Worker/OCM.Import.Worker.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/Tests/OCM.API.Tests/OCM.API.Tests.csproj b/Tests/OCM.API.Tests/OCM.API.Tests.csproj index ad8aa723..24465823 100644 --- a/Tests/OCM.API.Tests/OCM.API.Tests.csproj +++ b/Tests/OCM.API.Tests/OCM.API.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 false @@ -52,13 +52,13 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - + + + + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Website/OCM.Web/OCM.Web.csproj b/Website/OCM.Web/OCM.Web.csproj index 4b50931e..826496f6 100644 --- a/Website/OCM.Web/OCM.Web.csproj +++ b/Website/OCM.Web/OCM.Web.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 OCM.Web Exe @@ -20,8 +20,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive