[Python-ideas] Json object-level serializer (original) (raw)
Tarek Ziadé ziade.tarek at gmail.com
Thu Jul 29 14:39:09 CEST 2010
- Previous message: [Python-ideas] Json object-level serializer
- Next message: [Python-ideas] Json object-level serializer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, Jul 29, 2010 at 2:22 PM, Georg Brandl <g.brandl at gmx.net> wrote: ..
You can do this with a very short subclass of the JSONEncoder:
class MyJSONEncoder(JSONEncoder): def default(self, obj): return obj.json() # with a useful failure message I don't think it needs to be built into the default encoder.
Yes, but you need to customize in that case the encoding process and own it.
Having a builtin recognition of json would allow you to pass your objects to be serialized to any third party code that uses a plain json.dumps.
For instance, some web kits out there will automatically serialize your objects into json strings when you want to do json responses. e.g. it becomes a builtin adapter
Cheers Tarek
- Previous message: [Python-ideas] Json object-level serializer
- Next message: [Python-ideas] Json object-level serializer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]