appengine_js
appengine_js copied to clipboard
toJSON should return an object, not a string
JSON.stringify uses value returned by toJSON and serializes it to string, so it should be an object. Currenty Model objects are double-serialized when using JSON.stringify on them.
Please refer to:
When an object value is found, if the object contains a toJSON
method, its toJSON method will be called and the result will be
stringified. A toJSON method does not serialize: it returns the
value represented by the name/value pair that should be serialized,
or undefined if nothing should be serialized.
https://github.com/douglascrockford/JSON-js/blob/master/json.js#L75-81
So basically toData method should be called toJSON, and current toJSON is not needed at all (or call it toJSONString)