Skip to content

Commit b064ecf

Browse files
Copilotmarcominerva
andcommitted
Fix null model exception in JsonDocumentExtensions
Co-authored-by: marcominerva <3522534+marcominerva@users.noreply.github.com>
1 parent b4879c1 commit b064ecf

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/PdfSmith.BusinessLayer/Extensions/JsonDocumentExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace PdfSmith.BusinessLayer.Extensions;
77

88
public static class JsonDocumentExtensions
99
{
10-
public static object ToExpandoObject(this JsonDocument document, TimeZoneInfo? timeZoneInfo)
10+
public static object? ToExpandoObject(this JsonDocument document, TimeZoneInfo? timeZoneInfo)
1111
=> ConvertElement(document.RootElement, timeZoneInfo);
1212

13-
private static object ConvertElement(JsonElement element, TimeZoneInfo? timeZoneInfo)
13+
private static object? ConvertElement(JsonElement element, TimeZoneInfo? timeZoneInfo)
1414
{
1515
if (element.ValueKind == JsonValueKind.Object)
1616
{
@@ -27,7 +27,8 @@ private static object ConvertElement(JsonElement element, TimeZoneInfo? timeZone
2727
return element.EnumerateArray().Select(e => ConvertValue(e, timeZoneInfo)).ToList();
2828
}
2929

30-
throw new InvalidOperationException($"Unsupported JSON ValueKind: {element.ValueKind}");
30+
// For all other cases (including Null), delegate to ConvertValue which handles them properly
31+
return ConvertValue(element, timeZoneInfo);
3132
}
3233

3334
private static object? ConvertValue(JsonElement element, TimeZoneInfo? timeZoneInfo)

0 commit comments

Comments
 (0)