Starcounter-Jack / JSON-Patch

Lean and mean Javascript implementation of the JSON-Patch standard (RFC 6902). Update JSON documents using delta patches.
MIT License
1.79k stars 215 forks source link

[BUG]generate error patch document when object has Date field #272

Closed fissssssh closed 7 months ago

fissssssh commented 3 years ago

i wrote this code:

const obj = { date1: new Date(), date2: new Date() };
const observer = jsonpatch.observe<any>(obj);
const patchDoc = jsonpatch.generate(observer);
console.log(patchDoc);
observer.unobserve();

and then output:

[
    {
        "op": "replace",
        "path": "/date2",
        "value": "2021-04-16T14:11:13.382Z"
    },
    {
        "op": "replace",
        "path": "/date1",
        "value": "2021-04-16T14:11:13.382Z"
    }
]

absolutly i didn't do anythiny but there are two patches, so i view the source code found the error file: src/duplex.ts line:128

 _generate(mirror.value, observer.object, observer.patches, "", invertible);

should use mirror.obj instead mirror.value please fix it as soon as possible.

vvenegasv commented 2 years ago

We have the same issue. Any plans to fix it?

fissssssh commented 2 years ago

We have the same issue. Any plans to fix it?

replace Date with Unix Timestamp (long)

timarnoldev commented 7 months ago

Is there a fork on npm fixing this issue?