diff --git a/v2/jsonpatch.go b/v2/jsonpatch.go index 0d7823b..d88162f 100644 --- a/v2/jsonpatch.go +++ b/v2/jsonpatch.go @@ -70,12 +70,14 @@ func CreatePatch(a, b []byte) ([]Operation, error) { } var aI interface{} var bI interface{} - err := json.Unmarshal(a, &aI) - if err != nil { + aDec := json.NewDecoder(bytes.NewReader(a)) + aDec.UseNumber() + if err := aDec.Decode(&aI); err != nil { return nil, errBadJSONDoc } - err = json.Unmarshal(b, &bI) - if err != nil { + bDec := json.NewDecoder(bytes.NewReader(b)) + bDec.UseNumber() + if err := bDec.Decode(&bI); err != nil { return nil, errBadJSONDoc } return handleValues(aI, bI, "", []Operation{}) @@ -94,6 +96,11 @@ func matchesValue(av, bv interface{}) bool { if ok && bt == at { return true } + case json.Number: + bt, ok := bv.(json.Number) + if ok && bt == at { + return true + } case float64: bt, ok := bv.(float64) if ok && bt == at { @@ -212,7 +219,7 @@ func handleValues(av, bv interface{}, p string, patch []Operation) ([]Operation, if err != nil { return nil, err } - case string, float64, bool: + case string, float64, bool, json.Number: if !matchesValue(av, bv) { patch = append(patch, NewOperation("replace", p, bv)) } diff --git a/v2/jsonpatch_test.go b/v2/jsonpatch_test.go index c311159..07228a2 100644 --- a/v2/jsonpatch_test.go +++ b/v2/jsonpatch_test.go @@ -16,6 +16,7 @@ var simpleD = `{"a":100, "b":200, "c":"hello", "d":"foo"}` var simpleE = `{"a":100, "b":200}` var simplef = `{"a":100, "b":100, "d":"foo"}` var simpleG = `{"a":100, "b":null, "d":"foo"}` +var simpleH = `{"a":100, "b":200, "c":"hello", "d": 9223372036854775500}` var empty = `{}` var arraySrc = ` @@ -859,6 +860,7 @@ func TestCreatePatch(t *testing.T) { {"Simple:OneAdd", simpleA, simpleD}, {"Simple:OneRemove", simpleA, simpleE}, {"Simple:VsEmpty", simpleA, empty}, + {"Simple:AddBigInt", simpleA, simpleH}, // array types {"Array:Same", arraySrc, arraySrc}, {"Array:BoolReplace", arraySrc, arrayDst},