msgpack-lite icon indicating copy to clipboard operation
msgpack-lite copied to clipboard

Support toJSON?

Open endel opened this issue 8 years ago • 1 comments

I'm wondering if it's feasible to implement toJSON support on msgpack-lite?

JSON.stringify() supports handling custom toJSON methods, like:

function MyData () {}
MyData.prototype.toJSON = function() {
  return { custom: new Custom(), output: 2 };
}
function Custom() {}
Custom.prototype.toJSON = function() { return "recursive"; }

JSON.stringify(new MyData())
// => "{"custom":"recursive","output":2}"

Would be great to have the ability to customize the serialization for msgpack too.

Cheers!

endel avatar Oct 29 '17 04:10 endel

Some of Objects already support toJSON() serializing method. It sounds a good idea to divert it for us instead of building our own toMsgpack() method. Thanks.

kawanet avatar Nov 27 '17 10:11 kawanet