Rich-Harris/devalue

Error: Cannot stringify arbitrary non-POJOs on Object that have a toJSON method

victor-perez opened this issue · 1 comments

If you have for example this code, I would expect that the toJSON method will be called of the object but instead it throws a non-POJOs error.

var devalue = require("devalue")
var { Map } = require('immutable');
console.log(devalue({
    test: new Map({a:1})
}))

The purpose of devalue is to create a string representation of objects in memory that has 100% fidelity — i.e., by evaluating the string, you get exactly the same structure as existing before serialization.

If it called toJSON methods, it would no longer provide that guarantee. It's therefore out of scope for this project, so I'll close this issue — thanks