Skip to content

Commit dd885de

Browse files
committed
Merge branch 'fix/raps-edit-permissions' into Development
2 parents eac79c6 + b84908b commit dd885de

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

test/RAPS/EmptyDateBindingTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public void MemberPermissionBody_WithRealDates_StillBinds()
2525
var model = DeserializeMemberPermission(
2626
@"{""memberId"":""12345678"",""permissionId"":5,""access"":1,""startDate"":""2026-01-15T00:00:00"",""endDate"":""2026-06-30T00:00:00""}");
2727

28-
Assert.Equal(new DateTime(2026, 1, 15, 0, 0, 0, DateTimeKind.Local), model.StartDate);
29-
Assert.Equal(new DateTime(2026, 6, 30, 0, 0, 0, DateTimeKind.Local), model.EndDate);
28+
Assert.Equal(new DateTime(2026, 1, 15, 0, 0, 0, DateTimeKind.Unspecified), model.StartDate);
29+
Assert.Equal(new DateTime(2026, 6, 30, 0, 0, 0, DateTimeKind.Unspecified), model.EndDate);
3030
}
3131

3232
[Fact]
@@ -51,7 +51,7 @@ public void MemberPermission_RoundTripsThroughSerialization()
5151
MemberId = "12345678",
5252
PermissionId = 5,
5353
Access = 1,
54-
StartDate = new DateTime(2026, 1, 15, 0, 0, 0, DateTimeKind.Local),
54+
StartDate = new DateTime(2026, 1, 15, 0, 0, 0, DateTimeKind.Unspecified),
5555
EndDate = null
5656
};
5757

@@ -60,7 +60,7 @@ public void MemberPermission_RoundTripsThroughSerialization()
6060
JsonSerializer.Deserialize<MemberPermissionCreateUpdate>(json, JsonSerializerOptions.Web);
6161

6262
Assert.NotNull(result);
63-
Assert.Equal(new DateTime(2026, 1, 15, 0, 0, 0, DateTimeKind.Local), result.StartDate);
63+
Assert.Equal(new DateTime(2026, 1, 15, 0, 0, 0, DateTimeKind.Unspecified), result.StartDate);
6464
Assert.Null(result.EndDate);
6565
}
6666

web/Classes/Utilities/EmptyStringAsNullConverter.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ namespace Viper.Classes.Utilities;
88
/// A cleared date input posts "", which System.Text.Json otherwise rejects for
99
/// DateTime?/DateOnly?, failing model binding with a 400 before the action runs.
1010
/// Apply per property with [JsonConverter(typeof(EmptyStringAsNullConverter&lt;DateTime&gt;))].
11+
/// A JSON null never reaches these methods: HandleNull defaults to false for a
12+
/// converter over Nullable&lt;T&gt;, so System.Text.Json reads and writes null itself.
1113
/// </summary>
1214
public class EmptyStringAsNullConverter<T> : JsonConverter<T?> where T : struct
1315
{
1416
public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
1517
{
16-
if (reader.TokenType == JsonTokenType.Null)
17-
{
18-
return null;
19-
}
2018
if (reader.TokenType == JsonTokenType.String && string.IsNullOrWhiteSpace(reader.GetString()))
2119
{
2220
return null;
@@ -27,13 +25,10 @@ public class EmptyStringAsNullConverter<T> : JsonConverter<T?> where T : struct
2725

2826
public override void Write(Utf8JsonWriter writer, T? value, JsonSerializerOptions options)
2927
{
28+
// Nothing to write when null, since that case is handled before it gets here.
3029
if (value.HasValue)
3130
{
3231
JsonSerializer.Serialize(writer, value.Value, options);
3332
}
34-
else
35-
{
36-
writer.WriteNullValue();
37-
}
3833
}
3934
}

0 commit comments

Comments
 (0)