NicolasPetton/amber — Issue #117: Simple method for archiving/unarchiving Objects in JSON
Author: AmberMilanEskridge
Created: 2011-12-22 16:47:04+00:00
State: open

The `JSON.stringify` method allows simple archiving of Amber-objects into JSON. However the recreation of the objects from the JSON is not standarized, I think.

I'd love to get some standarized way to do something like `Person fromJSON: aResponse` for creating working instance of Person.

I propose the following idea in st-pseudocode.

`Object>>#toJSON` includes the klass of the object unless native.

Object>>#fromJSON: aJsonOrNative
| instance klass |
instance := self nativeFrom: aJsonOrNative.
instance ifNotNil: [^ instance].

klass := Smalltalk at: (aJsonOrNative at: #klass).
instance := klass basicNew.

klass instanceVariableNames
do: [:each | instance
basicAt: each
put: (Object fromJSON: (aHashedCollection at: each asIvarName))].

^ instance awakeFromJSON