From fdd75ee850132fb9da8b3a06c63eeb7d01d86c0f Mon Sep 17 00:00:00 2001 From: Marcus Kimpenhaus Date: Thu, 11 Dec 2025 13:50:45 +0100 Subject: [PATCH] feat: add non-generic Deserialize method with dynamic code requirements for JSON serialization --- src/KubernetesClient/KubernetesJson.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/KubernetesClient/KubernetesJson.cs b/src/KubernetesClient/KubernetesJson.cs index 35cfe3ac..286b110f 100644 --- a/src/KubernetesClient/KubernetesJson.cs +++ b/src/KubernetesClient/KubernetesJson.cs @@ -4,6 +4,7 @@ using System.Xml; #if NET8_0_OR_GREATER +using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization.Metadata; #endif @@ -127,6 +128,13 @@ public static void AddJsonOptions(Action configure) configure(JsonSerializerOptions); } +#if NET8_0_OR_GREATER + [RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")] + [RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] +#endif + public static object Deserialize(string json, Type returnType, JsonSerializerOptions jsonSerializerOptions = null) + => JsonSerializer.Deserialize(json, returnType, jsonSerializerOptions ?? JsonSerializerOptions); + public static TValue Deserialize(string json, JsonSerializerOptions jsonSerializerOptions = null) { #if NET8_0_OR_GREATER @@ -217,4 +225,4 @@ public static string Serialize(JsonNode value, JsonSerializerOptions jsonSeriali #endif } } -} +} \ No newline at end of file