Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug with serializing anything using Nullable DateTimes #605

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PinguApps.Appwrite.Shared/Constants.cs
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@ public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerialize
{
_dateTimeConverter.Write(writer, value.Value, options);
}
else
{
writer.WriteNullValue();
}
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}
}
Loading