Skip to content

Commit

Permalink
Update custom JSON deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
millicentachieng committed Mar 25, 2024
1 parent e318683 commit 265dbbd
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions ApiDoctor.Validation/Config/DocumentOutlineFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,22 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
var jArray = JArray.Load(reader);
foreach (var item in jArray)
{
if (item["condition"] != null)
if (item is JObject jObject)
{
var conditionalHeader = item.ToObject<ConditionalDocumentHeader>(serializer);
allowedHeaders.Add(conditionalHeader);
}
else if (item["title"] != null)
{
var expectedHeader = item.ToObject<ExpectedDocumentHeader>(serializer);
allowedHeaders.Add(expectedHeader);
object header;
if (jObject.ContainsKey("condition"))
{
header = jObject.ToObject<ConditionalDocumentHeader>(serializer);
}
else if (jObject.ContainsKey("title"))
{
header = jObject.ToObject<ExpectedDocumentHeader>(serializer);
}
else
{
throw new JsonReaderException("Invalid document header definition");
}
allowedHeaders.Add(header);
}
else
{
Expand Down

0 comments on commit 265dbbd

Please sign in to comment.