Skip to content

Commit

Permalink
add status property deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
smokedlinq committed Oct 1, 2022
1 parent 62fc1d3 commit ff1a125
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public override HealthReport Read(ref Utf8JsonReader reader, Type typeToConvert,
var healthReportOptions = HealthReportJsonSerializerOptionsFactory.Create(options);
Dictionary<string, HealthReportEntry>? entries = null;
var totalDuration = TimeSpan.Zero;
HealthStatus? status = null;

while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
{
Expand All @@ -25,6 +26,11 @@ public override HealthReport Read(ref Utf8JsonReader reader, Type typeToConvert,

switch (healthReportOptions.PropertyNameCaseInsensitive ? propertyName : propertyName?.ToLowerInvariant())
{
case "Status":
case "status":
status = JsonSerializer.Deserialize<HealthStatus>(ref reader, healthReportOptions);
break;

case "TotalDuration":
case "totalDuration":
case "totalduration":
Expand All @@ -39,7 +45,11 @@ public override HealthReport Read(ref Utf8JsonReader reader, Type typeToConvert,
}
}

return new HealthReport(entries ?? new(), totalDuration);
var report = status is null
? new HealthReport(entries ?? new(), totalDuration)
: new HealthReport(entries ?? new(), status.Value, totalDuration);

return report;
}

public override void Write(Utf8JsonWriter writer, HealthReport value, JsonSerializerOptions options)
Expand Down

0 comments on commit ff1a125

Please sign in to comment.