Skip to content

Commit 8909179

Browse files
committed
don't remove empty array if it was already empty
1 parent 40ff453 commit 8909179

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/PartialResponse.AspNetCore.Mvc.Formatters.Json/Internal/JsonSerializerExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,17 @@ public static void Serialize(this JsonSerializer jsonSerializer, JsonWriter json
6262

6363
private static void RemoveArrayElements(JArray array, string currentPath, SerializerContext context)
6464
{
65+
var containsChildItems = array.Count > 0;
66+
6567
array.OfType<JObject>()
6668
.ToList()
6769
.ForEach(childObject => RemoveObjectProperties(childObject, currentPath, context));
6870

69-
RemoveArrayIfEmpty(array);
71+
// PartialResponse should only remove an array when it initially contained items, but was empty after filtering.
72+
if (containsChildItems)
73+
{
74+
RemoveArrayIfEmpty(array);
75+
}
7076
}
7177

7278
private static void RemoveArrayIfEmpty(JArray array)

0 commit comments

Comments
 (0)