We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
I am using SystemTextJson.JsonDiffPatch 2.0.0 on .Net 8.
Given this TestClass, I want diffs to include CompareMe and excludeIgnoreMe.
TestClass
CompareMe
IgnoreMe
public class TestClass { public int CompareMe { get; set; } public int IgnoreMe { get; set; } }
When both left and right are not null, the diff correctly excludes IgnoreMe.
left
right
public void BothNotNull() { TestClass left = new TestClass() { CompareMe = 1, IgnoreMe = 1 }; TestClass right = new TestClass() { CompareMe = 2, IgnoreMe = 2 }; string leftJson = JsonSerializer.Serialize(left); string rightJson = JsonSerializer.Serialize(right); JsonDiffOptions options = new JsonDiffOptions() { PropertyFilter = (prop, _) => !StringComparer.Ordinal.Equals(prop, nameof(TestClass.IgnoreMe)), }; JsonNode? diff = JsonDiffPatcher.Diff(leftJson, rightJson, options); string diffJson = diff!.ToJsonString(); // {"CompareMe":[1,2]} }
But if one of left and right is null then the JsonDiffOptions.PropertyFilter function doesn't run and the diff includes IgnoreMe.
JsonDiffOptions.PropertyFilter
public void LeftNull() { TestClass? left = null; TestClass right = new TestClass() { CompareMe = 2, IgnoreMe = 2 }; string leftJson = JsonSerializer.Serialize(left); string rightJson = JsonSerializer.Serialize(right); JsonDiffOptions options = new JsonDiffOptions() { PropertyFilter = (prop, _) => !StringComparer.Ordinal.Equals(prop, nameof(TestClass.IgnoreMe)), }; JsonNode? diff = JsonDiffPatcher.Diff(leftJson, rightJson, options); string diffJson = diff!.ToJsonString(); // [null,{"CompareMe":2,"IgnoreMe":2}] // expected diffJson to be [null,{"CompareMe":2}] } public void RightNull() { TestClass left = new TestClass() { CompareMe = 1, IgnoreMe = 1 }; TestClass? right = null; string leftJson = JsonSerializer.Serialize(left); string rightJson = JsonSerializer.Serialize(right); JsonDiffOptions options = new JsonDiffOptions() { PropertyFilter = (prop, _) => !StringComparer.Ordinal.Equals(prop, nameof(TestClass.IgnoreMe)), }; JsonNode? diff = JsonDiffPatcher.Diff(leftJson, rightJson, options); string diffJson = diff!.ToJsonString(); // [{"CompareMe":1,"IgnoreMe":1},null] // expected diffJson to be [{"CompareMe":1},null] }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I am using SystemTextJson.JsonDiffPatch 2.0.0 on .Net 8.
Given this
TestClass
, I want diffs to includeCompareMe
and excludeIgnoreMe
.When both
left
andright
are not null, the diff correctly excludesIgnoreMe
.But if one of
left
andright
is null then theJsonDiffOptions.PropertyFilter
function doesn't run and the diff includesIgnoreMe
.The text was updated successfully, but these errors were encountered: