Handle both strings and objects in Base.importJson().

And keep returning strings from #exportJson().
This commit is contained in:
Jürg Lehni 2013-04-05 16:58:00 +02:00
parent 9d2fd2f675
commit 9adfc01c8d

View file

@ -61,9 +61,6 @@ this.Base = Base.inject(/** @lends Base# */{
// To support JSON.stringify:
toJSON: function() {
// TODO: We should probably have exportJson() / importJson() deal with
// objects rather than strings too, so we can just delegate to those
// here.
return Base.serialize(this);
},
@ -382,7 +379,8 @@ this.Base = Base.inject(/** @lends Base# */{
},
importJson: function(json) {
return Base.deserialize(JSON.parse(json));
return Base.deserialize(
typeof json === 'string' ? JSON.parse(json) : json);
},
/**