wbish/jsondiffpatch.net

Array Items not being diffed when item moves to end of array

d1820 opened this issue · 0 comments

d1820 commented

An existing array item that gets moved to the end of an array does not get included in the diff results

Unit Test Code

protected readonly string _testDoc = @"{
                                              ""PartitionKey"": ""StoreFront.4aab3661-b697-4557-936f-1cd457328e5d"",
                                              ""id"": ""12345"",
                                              ""IsActive"": true,
                                              ""StoreDomain"": ""test.com"",
                                              ""Items"": [""test1"", ""test2""],
                                              ""LastModifiedOn"": ""2017-11-03T10:08:48.0532074-07:00"",
                                              ""LastModifiedBy"": ""test"",
                                              ""CreatedOn"": ""2017-11-03T10:08:48.0532074-07:00"",
                                              ""CreatedBy"": ""test"",
                                              ""Test"": {""FieldResponses"":[{""Key"":""PurchaserSSN"", ""Type"":""ga-secure-socialsecurity"",""Response"": ""333-33-3333"",""ResponseContext"":null}, {""Key"":""PurchaserID"", ""Type"":""ga-secure-textbox"",""Response"":""securetext"",""ResponseContext"":null}]}
                                            }";

        protected readonly string _changedDoc = @"{
                                              ""PartitionKey"": ""StoreFront.4aab3661-b697-4557-936f-1cd457328e5d"",
                                              ""id"": ""12345"",
                                              ""IsActive"": true,
                                              ""StoreDomain"": ""test.com"",
                                              ""Items"": [""test3"", ""test4"", ""test2""],
                                              ""LastModifiedOn"": ""2017-11-03T10:08:48.0532074-07:00"",
                                              ""LastModifiedBy"": ""test"",
                                              ""CreatedOn"": ""2017-11-03T10:08:48.0532074-07:00"",
                                              ""CreatedBy"": ""test"",
                                              ""Test"": {""FieldResponses"":[{""Key"":""PurchaserSSN"", ""Type"":""ga-secure-socialsecurity"",""Response"": ""555-55-5555"",""ResponseContext"":null}, {""Key"":""PurchaserID"", ""Type"":""ga-secure-textbox"",""Response"":""newValue"",""ResponseContext"":null}, {""Key"":""NewItem"", ""Type"":""ga-secure-textbox"",""Response"":""NewItemValue"",""ResponseContext"": {""test"": ""test""}}]}
                                            }";

        [Fact]
        public async Task TEST()
        {
            var d1 = CreateDocument(_testDoc);
            var d2 = CreateDocument(_changedDoc);
            var jdp = new JsonDiffPatch(new Options
            {
                ArrayDiff = ArrayDiffMode.Efficient,
                TextDiff = TextDiffMode.Simple
            });
            var diffObj = jdp.Diff(previousDocument, newDoc);
        }
		
		public JObject CreateDocument(string json)
        {
            return JObject.Parse(json);
        }

If you examine the output you can see it drops the "test2" item from the diff

2019-05-09_161731

If the "test2" is moved anywhere else i the array it is matched and a delta is created. Due to this Can not use this diff tool completely, will have to use this and write custom array diff code, unless a quick patch and push can be done to fix this issue.

Related to #14 ??