JSON-Patch icon indicating copy to clipboard operation
JSON-Patch copied to clipboard

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

Open fissssssh opened this issue 4 years ago • 2 comments
trafficstars

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.

fissssssh avatar Apr 16 '21 14:04 fissssssh

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

vvenegasv avatar Jan 07 '22 14:01 vvenegasv

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

replace Date with Unix Timestamp (long)

fissssssh avatar Jan 11 '22 08:01 fissssssh

Is there a fork on npm fixing this issue?

timarnoldev avatar Jan 20 '24 16:01 timarnoldev