Skip to content

Commit d7af9d3

Browse files
authored
Merge pull request #21 from dotarj/refactor-should-serialize-method
should serialize return value changed
2 parents 6aa0d7f + f26fcfa commit d7af9d3

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,15 @@ public static void Serialize(this JsonSerializer jsonSerializer, JsonWriter json
3434
var context = new SerializerContext(shouldSerialize);
3535
var token = JToken.FromObject(value, jsonSerializer);
3636

37-
var array = token as JArray;
38-
39-
if (array != null)
37+
if (token is JArray array)
4038
{
4139
RemoveArrayElements(array, null, context);
4240

4341
array.WriteTo(jsonWriter);
4442
}
4543
else
4644
{
47-
var @object = token as JObject;
48-
49-
if (@object != null)
45+
if (token is JObject @object)
5046
{
5147
RemoveObjectProperties(@object, null, context);
5248

@@ -97,7 +93,7 @@ private static void RemoveObjectProperties(JObject @object, string currentPath,
9793
{
9894
var path = CombinePath(currentPath, property.Name);
9995

100-
return context.ShouldSerialize(path);
96+
return !context.ShouldSerialize(path);
10197
})
10298
.ToList()
10399
.ForEach(property => property.Remove());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public bool ShouldSerialize(string path)
2222
return this.cache[path];
2323
}
2424

25-
var result = !this.shouldSerialize(path);
25+
var result = this.shouldSerialize(path);
2626

2727
this.cache.Add(path, result);
2828

0 commit comments

Comments
 (0)