Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty patch when compare two arrays #14

Open
tochti opened this issue Mar 14, 2018 · 3 comments
Open

Empty patch when compare two arrays #14

tochti opened this issue Mar 14, 2018 · 3 comments

Comments

@tochti
Copy link

tochti commented Mar 14, 2018

Hello,

first thanks for your effort creating this library.

I was wondering if the following behavior is intended?

Actual Behavior

If the following code is executed the result is an empty patch.
The reason for that is that the 2nd item in o2 is the "same" item like the item in o1.

import (
	"fmt"

	"github.com/mattbaird/jsonpatch"
)

func main() {

	o1 := []byte(`{"Items":[{"K":1}]}`)
	o2 := []byte(`{"Items":[{"K":1},{"K":1}]}`)

	patch, err := jsonpatch.CreatePatch(o1, o2)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Patch", patch)

}

Expected Behavior

I did expect to get the following patch

[{"op": "add", "path": "/Items/1", "value": {"K":1}}]

Specifications

Version: newest (go get github.com/mattbaird/jsonpatch)

@mengqiy
Copy link

mengqiy commented Jan 7, 2019

@tamalsaha Is this issue fixed in your fork?

@tamalsaha
Copy link

I believe so. You can add the test to https://github.com/appscode/jsonpatch/blob/master/jsonpatch_test.go and double check.

@tamalsaha
Copy link

@mengqiy , I believe this array test case is covered by https://github.com/appscode/jsonpatch/blob/master/jsonpatch_test.go#L758

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants