Skip to content
10 changes: 9 additions & 1 deletion src/KubernetesClient/KubernetesJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Xml;

#if NET8_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization.Metadata;
#endif

Expand All @@ -24,7 +25,7 @@
public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
{
var iso8601TimeSpanString = XmlConvert.ToString(value); // XmlConvert for TimeSpan uses ISO8601, so delegate serialization to it
writer.WriteStringValue(iso8601TimeSpanString);

Check warning on line 28 in src/KubernetesClient/KubernetesJson.cs

View workflow job for this annotation

GitHub Actions / e2e

In externally visible method 'void Iso8601TimeSpanConverter.Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)', validate parameter 'writer' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)
}
}

Expand Down Expand Up @@ -66,7 +67,7 @@
{
// No fractional seconds - use format without fractional part
var basePart = date.ToString("yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture);
writer.WriteStringValue(basePart + "Z");

Check warning on line 70 in src/KubernetesClient/KubernetesJson.cs

View workflow job for this annotation

GitHub Actions / e2e

In externally visible method 'void KubernetesDateTimeOffsetConverter.Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)', validate parameter 'writer' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)
}
else
{
Expand Down Expand Up @@ -127,6 +128,13 @@
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<TValue>(string json, JsonSerializerOptions jsonSerializerOptions = null)
{
#if NET8_0_OR_GREATER
Expand Down Expand Up @@ -180,7 +188,7 @@
public static string Serialize(object value, JsonSerializerOptions jsonSerializerOptions = null)
{
#if NET8_0_OR_GREATER
var info = (jsonSerializerOptions ?? JsonSerializerOptions).GetTypeInfo(value.GetType());

Check warning on line 191 in src/KubernetesClient/KubernetesJson.cs

View workflow job for this annotation

GitHub Actions / e2e

In externally visible method 'string KubernetesJson.Serialize(object value, JsonSerializerOptions jsonSerializerOptions = null)', validate parameter 'value' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)
return JsonSerializer.Serialize(value, info);
#else
return JsonSerializer.Serialize(value, jsonSerializerOptions ?? JsonSerializerOptions);
Expand All @@ -190,7 +198,7 @@
public static string Serialize(JsonDocument value, JsonSerializerOptions jsonSerializerOptions = null)
{
#if NET8_0_OR_GREATER
var info = (jsonSerializerOptions ?? JsonSerializerOptions).GetTypeInfo(value.GetType());

Check warning on line 201 in src/KubernetesClient/KubernetesJson.cs

View workflow job for this annotation

GitHub Actions / e2e

In externally visible method 'string KubernetesJson.Serialize(JsonDocument value, JsonSerializerOptions jsonSerializerOptions = null)', validate parameter 'value' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)
return JsonSerializer.Serialize(value, info);
#else
return JsonSerializer.Serialize(value, jsonSerializerOptions ?? JsonSerializerOptions);
Expand All @@ -210,11 +218,11 @@
public static string Serialize(JsonNode value, JsonSerializerOptions jsonSerializerOptions = null)
{
#if NET8_0_OR_GREATER
var info = (jsonSerializerOptions ?? JsonSerializerOptions).GetTypeInfo(value.GetType());

Check warning on line 221 in src/KubernetesClient/KubernetesJson.cs

View workflow job for this annotation

GitHub Actions / e2e

In externally visible method 'string KubernetesJson.Serialize(JsonNode value, JsonSerializerOptions jsonSerializerOptions = null)', validate parameter 'value' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)
return JsonSerializer.Serialize(value, info);
#else
return JsonSerializer.Serialize(value, jsonSerializerOptions ?? JsonSerializerOptions);
#endif
}
}
}
}
Loading