[Python-ideas] Json object-level serializer

Tarek Ziadé ziade.tarek at gmail.com
Thu Jul 29 13:54:12 CEST 2010


On Thu, Jul 29, 2010 at 1:40 PM, Oleg Broytman <phd at phd.pp.ru> wrote:
> On Thu, Jul 29, 2010 at 01:35:41PM +0200, Tarek Ziad? wrote:
>>
>> What about adding in the json package the ability for an object to
>> provide a different object to serialize ?
>> This would be useful to translate a class into a structure that can be
>> passed to json.dumps
>>
>> So, it __json__ is provided, its used for serialization instead of the
>> object itself:
>
>   Also there must be a deserialization hook. Pickle uses __setstate__, and
> pickle stores the name of the class to call __setstate__ upon.

You cannot do a round trip because once the object is serialized, json
don't know which class
to instantiate to de-serialize it Which is fine really, since json
just serialize simple elements.


Cheers
Tarek

-- 
Tarek Ziadé | http://ziade.org



More information about the Python-ideas mailing list