Hi, I'm hoping to use CouchDB for storage on a seaside application. It would be lovely if I didn't have to serialize/de-serialize by hand to json for all my persistent objects, and could use instead something like a smalltalk version of Google's Gson library. Is there anything like that? I've tried the JSON library bundled with SCouchDB and it seems to automatically handle simple objects (eg, where the inst vars reference Strings or Numbers), but not handle more complex objects. Also, I haven't seen anything that de-serializes from json. Thanks much! Larry
Hi Larry, You can maybe try with Magritte ? http://forum.world.st/Magritte-gt-Json-td3727820.html should be a good starting point :) On 29/08/11 21:27, Larry White wrote:
Hi,
I'm hoping to use CouchDB for storage on a seaside application. It would be lovely if I didn't have to serialize/de-serialize by hand to json for all my persistent objects, and could use instead something like a smalltalk version of Google's Gson library. Is there anything like that?
I've tried the JSON library bundled with SCouchDB and it seems to automatically handle simple objects (eg, where the inst vars reference Strings or Numbers), but not handle more complex objects. Also, I haven't seen anything that de-serializes from json.
Thanks much!
Larry
Hi Larry, On 29 Aug 2011, at 21:27, Larry White wrote:
I've tried the JSON library bundled with SCouchDB and it seems to automatically handle simple objects (eg, where the inst vars reference Strings or Numbers), but not handle more complex objects. Also, I haven't seen anything that de-serializes from json.
There is a JSON encoder/decoder in Seaside, it is pretty standalone, see this recent thread: http://forum.world.st/Standalone-JSON-Package-tp3759705p3759705.html This one works very well (I am using it all the time), but only handles standard JSON types (follows the spec). Now, JSON objects don't hold their type or class as Smalltalk (or Java objects) do, they are just Dictionaries. There is no automagic solution to this, apart from encoding the type/class as a property, but will most probably not be portable across languages (java.lang.Integer for Java, Integer for Smalltalk), one of the strengths of JSON. So you will have to write code to convert your Person (or whatever) objects to/from Dictionaries and use JSON. Sven
Without having tried them, I see there are two CouchDB projects in squeaksource, they may handle your needs: http://www.squeaksource.com/SCouchDB.html http://www.squeaksource.com/CouchDB.html Cheers, 2011/8/30 Sven Van Caekenberghe <sven@beta9.be>
Hi Larry,
On 29 Aug 2011, at 21:27, Larry White wrote:
I've tried the JSON library bundled with SCouchDB and it seems to automatically handle simple objects (eg, where the inst vars reference Strings or Numbers), but not handle more complex objects. Also, I haven't seen anything that de-serializes from json.
There is a JSON encoder/decoder in Seaside, it is pretty standalone, see this recent thread:
http://forum.world.st/Standalone-JSON-Package-tp3759705p3759705.html
This one works very well (I am using it all the time), but only handles standard JSON types (follows the spec).
Now, JSON objects don't hold their type or class as Smalltalk (or Java objects) do, they are just Dictionaries. There is no automagic solution to this, apart from encoding the type/class as a property, but will most probably not be portable across languages (java.lang.Integer for Java, Integer for Smalltalk), one of the strengths of JSON.
So you will have to write code to convert your Person (or whatever) objects to/from Dictionaries and use JSON.
Sven
-- Bernat Romagosa.
Wow. Thanks for all the replies. @Bernat. I am using the SCouchDB library, but will take a look at the other one. Thanks. @Sven. I'll also take a look at that Json library. Thank you. @Markus. It has to Json, for exactly the reason that @Davorin suggests. @Francois. I'm looking at Magritte as well, but it seems a bit overwhelming for a Smalltalk noob. I may give it a try on my next project. Apologies for the naivete of the original question. It wasn't 'til I tried writing my own that I realized (doh) that you can't write something like Gson in Java without augmenting the model with type information. I assume that's how Magritte does it, since it seems to be all about meta data. On Tue, Aug 30, 2011 at 5:30 AM, Bernat Romagosa < tibabenfortlapalanca@gmail.com> wrote:
Without having tried them, I see there are two CouchDB projects in squeaksource, they may handle your needs:
http://www.squeaksource.com/SCouchDB.html http://www.squeaksource.com/CouchDB.html
Cheers,
2011/8/30 Sven Van Caekenberghe <sven@beta9.be>
Hi Larry,
On 29 Aug 2011, at 21:27, Larry White wrote:
I've tried the JSON library bundled with SCouchDB and it seems to automatically handle simple objects (eg, where the inst vars reference Strings or Numbers), but not handle more complex objects. Also, I haven't seen anything that de-serializes from json.
There is a JSON encoder/decoder in Seaside, it is pretty standalone, see this recent thread:
http://forum.world.st/Standalone-JSON-Package-tp3759705p3759705.html
This one works very well (I am using it all the time), but only handles standard JSON types (follows the spec).
Now, JSON objects don't hold their type or class as Smalltalk (or Java objects) do, they are just Dictionaries. There is no automagic solution to this, apart from encoding the type/class as a property, but will most probably not be portable across languages (java.lang.Integer for Java, Integer for Smalltalk), one of the strengths of JSON.
So you will have to write code to convert your Person (or whatever) objects to/from Dictionaries and use JSON.
Sven
-- Bernat Romagosa.
participants (4)
-
Bernat Romagosa -
Francois Stephany -
Larry White -
Sven Van Caekenberghe