Closed
Description
> Immutable = require('immutable')
> Model = Immutable.Record({})
[Function: Record]
> Model.prototype.toJSON = function() { return 'model' }
[Function]
> JSON.stringify({ a: new Model() })
'{"a":"model"}'
> JSON.stringify(Immutable.Map({ a: new Model() }))
'{"a":{}}'
I expected the last line to return '{"a":"model"}'
.
I know toJSON
on iterables is an alias to toJS
and calls toJS
recursively which is why the Model
's toJSON
isn't called at all. Perhaps toJSON
should instead call toJSON
recursively which gives us a more familiar way to override the serialization behavior?
Metadata
Metadata
Assignees
Labels
No labels