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"; } 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); + } }