From 763a0e7ef0650ced7e3c009d4a89569fd3819451 Mon Sep 17 00:00:00 2001 From: Matthew Parker Date: Fri, 3 Jan 2025 01:12:31 +0000 Subject: [PATCH 1/2] added a fix for serialization using the nullable datetime converter --- .../Converters/NullableDateTimeConverter.cs | 4 ++++ .../NullableDateTimeConverterTests.cs | 22 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/PinguApps.Appwrite.Shared/Converters/NullableDateTimeConverter.cs b/src/PinguApps.Appwrite.Shared/Converters/NullableDateTimeConverter.cs index 86df73fa..d134098d 100644 --- a/src/PinguApps.Appwrite.Shared/Converters/NullableDateTimeConverter.cs +++ b/src/PinguApps.Appwrite.Shared/Converters/NullableDateTimeConverter.cs @@ -29,5 +29,9 @@ public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerialize { _dateTimeConverter.Write(writer, value.Value, options); } + else + { + writer.WriteNullValue(); + } } } diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Converters/NullableDateTimeConverterTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Converters/NullableDateTimeConverterTests.cs index f050759f..89683ddc 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Converters/NullableDateTimeConverterTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Converters/NullableDateTimeConverterTests.cs @@ -1,4 +1,5 @@ -using System.Text.Json; +using System.Text; +using System.Text.Json; using System.Text.Json.Serialization; using PinguApps.Appwrite.Shared.Converters; @@ -94,4 +95,23 @@ public void Write_NullDateTimeInObject_WritesNullValue() var json = JsonSerializer.Serialize(new NullableDateTimeObject(), _options); Assert.Equal("{\"x\":null}", json); } + + [Fact] + public void Write_WhenValueIsNull_WritesNullValue() + { + // Arrange + var converter = new NullableDateTimeConverter(); + DateTime? nullDateTime = null; + + using var stream = new MemoryStream(); + using var writer = new Utf8JsonWriter(stream); + + // Act + converter.Write(writer, nullDateTime, _options); + writer.Flush(); + + // Assert + var json = Encoding.UTF8.GetString(stream.ToArray()); + Assert.Equal("null", json); + } } From 665ff097979d8d068e3a3761b91124d3e30d28fa Mon Sep 17 00:00:00 2001 From: Matthew Parker Date: Fri, 3 Jan 2025 01:13:11 +0000 Subject: [PATCH 2/2] bumped version --- src/PinguApps.Appwrite.Shared/Constants.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PinguApps.Appwrite.Shared/Constants.cs b/src/PinguApps.Appwrite.Shared/Constants.cs index 9adcb51e..519ac4d1 100644 --- a/src/PinguApps.Appwrite.Shared/Constants.cs +++ b/src/PinguApps.Appwrite.Shared/Constants.cs @@ -1,5 +1,5 @@ namespace PinguApps.Appwrite.Shared; public static class Constants { - public const string Version = "1.0.2"; + public const string Version = "1.0.3"; }