Closed dounan closed 6 years ago
Thank you so much for reporting the issue this nicely! While I see the issue with this, removing or changing this line wouldn't do Date objects any good. Dates are Javascript objects. Not JSON objects. We only support serializable JSON objects, and if you look at the RFC we implement it says:
JSON Patch defines a JSON document structure for expressing a sequence of operations to apply to a JavaScript Object Notation (JSON) document; it is suitable for use with the HTTP PATCH method. The "application/json-patch+json" media type is used to identify such patch documents.
So even if we remove this call, Dates will still be unserialzable and unsupported by JSON-Patch protocol and accordingly our library.
On line 194, there is a check to see if the object has a
toJSON
function, and setsobj = obj.toJSON()
if there is. https://github.com/Starcounter-Jack/JSON-Patch/blob/406a6ddba0165271e4e767ff9c41bcbbebdf307e/src/duplex.ts#L194The test for this case creates a function that returns an
Object
for thetoJSON()
function: https://github.com/Starcounter-Jack/JSON-Patch/blob/406a6ddba0165271e4e767ff9c41bcbbebdf307e/test/spec/duplexSpec.js#L586However, the javascript
Date
object also has atoJSON
method, but it returns a string instead of anObject
. Here is the output of comparing two date objects:Maybe this is the intended behavior, but just want to point it out just in case.