From 8caa3a33229ebc6312052e63458da90bdeeefb96 Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Sun, 16 Jun 2019 21:53:14 +0200 Subject: [PATCH] ref: Use System.Text.Json Not supporting [DataContract] See dotnet/corefx#33115 --- global.json | 2 +- src/Sentry.Protocol/Sentry.Protocol.csproj | 4 +-- test/Sentry.Protocol.Tests/JsonSerializer.cs | 19 +++++++++++++- .../Sentry.Protocol.Tests.csproj | 25 +++++++++++++------ 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/global.json b/global.json index 0a37afd..c3716c9 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "2.2.105" + "version": "3.0.100-preview6-012264" } } diff --git a/src/Sentry.Protocol/Sentry.Protocol.csproj b/src/Sentry.Protocol/Sentry.Protocol.csproj index 8e4d76a..e41ba2b 100644 --- a/src/Sentry.Protocol/Sentry.Protocol.csproj +++ b/src/Sentry.Protocol/Sentry.Protocol.csproj @@ -1,7 +1,7 @@  - netstandard2.0;netstandard1.3;net46;net45 + netcoreapp3.0;netstandard2.0;netstandard1.3;net45 7.2 Sentry.Protocol Sentry.Protocol @@ -15,7 +15,7 @@ - + HAS_VALUE_TUPLE;$(AdditionalConstants) diff --git a/test/Sentry.Protocol.Tests/JsonSerializer.cs b/test/Sentry.Protocol.Tests/JsonSerializer.cs index eff3300..bc8bf84 100644 --- a/test/Sentry.Protocol.Tests/JsonSerializer.cs +++ b/test/Sentry.Protocol.Tests/JsonSerializer.cs @@ -1,20 +1,37 @@ +#if HAS_SYSTEM_JSON +using System.Text.Json.Serialization; +using Json = System.Text.Json.Serialization.JsonSerializer; +#else using Newtonsoft.Json; using Newtonsoft.Json.Converters; +#endif namespace Sentry.Protocol.Tests { internal class JsonSerializer { +#if HAS_SYSTEM_JSON + + private static readonly JsonSerializerOptions Options = new JsonSerializerOptions() + { + IgnoreNullValues = true, + }; + + public static string SerializeObject(T @object) => Json.ToString(@object, Options); + public static dynamic DeserializeObject(string json) => Json.Parse(json); +#else private static readonly StringEnumConverter StringEnumConverter = new StringEnumConverter(); + private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings { ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor, NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None, - Converters = new[] { StringEnumConverter } + Converters = new[] {StringEnumConverter} }; public static string SerializeObject(T @object) => JsonConvert.SerializeObject(@object, Settings); public static dynamic DeserializeObject(string json) => JsonConvert.DeserializeObject(json); +#endif } } diff --git a/test/Sentry.Protocol.Tests/Sentry.Protocol.Tests.csproj b/test/Sentry.Protocol.Tests/Sentry.Protocol.Tests.csproj index 26571f7..ff34539 100644 --- a/test/Sentry.Protocol.Tests/Sentry.Protocol.Tests.csproj +++ b/test/Sentry.Protocol.Tests/Sentry.Protocol.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1;netcoreapp2.0 + netcoreapp3.0;netcoreapp2.1;netcoreapp2.0 $(TargetFrameworks);net45 @@ -10,23 +10,32 @@ + + HAS_VALUE_TUPLE;$(AdditionalConstants) + + - - - - - + - - HAS_VALUE_TUPLE;$(AdditionalConstants) + + + + + + HAS_VALUE_TUPLE;HAS_SYSTEM_JSON;$(AdditionalConstants) + + + + +