From 468f3d491188fe2be92398260dec9e41e46012e9 Mon Sep 17 00:00:00 2001 From: Maxwell Weru Date: Thu, 16 May 2024 07:12:55 +0300 Subject: [PATCH] Add primitive types to InsightsJsonSerializerContext that may be used with ProblemDetails.Extensions --- .../InsightsJsonSerializerContext.cs | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Tingle.AspNetCore.ApplicationInsights/InsightsJsonSerializerContext.cs b/src/Tingle.AspNetCore.ApplicationInsights/InsightsJsonSerializerContext.cs index 5c249dc..d327b1d 100644 --- a/src/Tingle.AspNetCore.ApplicationInsights/InsightsJsonSerializerContext.cs +++ b/src/Tingle.AspNetCore.ApplicationInsights/InsightsJsonSerializerContext.cs @@ -1,7 +1,37 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Nodes; +using System.Text.Json; +using System.Text.Json.Serialization; namespace Tingle.AspNetCore.ApplicationInsights; [JsonSerializable(typeof(IDictionary))] [JsonSerializable(typeof(IDictionary))] +// These primitive types are declared for common types that may be used with ProblemDetails.Extensions. +[JsonSerializable(typeof(bool))] +[JsonSerializable(typeof(byte))] +[JsonSerializable(typeof(sbyte))] +[JsonSerializable(typeof(short))] +[JsonSerializable(typeof(ushort))] +[JsonSerializable(typeof(int))] +[JsonSerializable(typeof(uint))] +[JsonSerializable(typeof(long))] +[JsonSerializable(typeof(ulong))] +[JsonSerializable(typeof(float))] +[JsonSerializable(typeof(double))] +[JsonSerializable(typeof(decimal))] +[JsonSerializable(typeof(char))] +[JsonSerializable(typeof(string))] +[JsonSerializable(typeof(DateTime))] +[JsonSerializable(typeof(DateTimeOffset))] +[JsonSerializable(typeof(TimeSpan))] +[JsonSerializable(typeof(JsonArray))] +[JsonSerializable(typeof(JsonObject))] +[JsonSerializable(typeof(JsonDocument))] +[JsonSerializable(typeof(DateOnly))] +[JsonSerializable(typeof(TimeOnly))] +#if NET8_0_OR_GREATER +[JsonSerializable(typeof(Half))] +[JsonSerializable(typeof(Int128))] +[JsonSerializable(typeof(UInt128))] +#endif internal partial class InsightsJsonSerializerContext : JsonSerializerContext { }