Re: JsonPickle & __setstate__/__getstate__

24 views
Skip to first unread message

David Aguilar

unread,
Oct 24, 2009, 2:31:56 AM10/24/09
to Eoghan Murray, jsonp...@googlegroups.com
On Wed, Oct 21, 2009 at 12:02:28PM +0100, Eoghan Murray wrote:
> Thanks David,
> I'll check out the newer version before the end of the week, I didn't
> know there was get/setstate support there (I'm running a patched
> version to support dict key objects).
> I copied the try/except style from the python pickle module.

No prob.

I remember the dict key stuff.
At the time I wasn't interested, but maybe it'd make it easier
on you if we turned your dict keys patch into an optional feature
that could be turned on/off at en/decode time, defaulting to off?
Then your dependency would be part of the official release,
tested, etc.

The referencing code needs a rework too. We want to be able to
reconstruct refs into array elements, and presumably it'd be
better if we were able to do so for any arbitrary objects as
keys, not just dicts, but dicts are a good starting point.

Let me know if you were able to port your patch to the latest
jsonpickle, it sounds useful. Once it's well tested then the
work of getting it to support refs like the following would be
something to think about:

class A(object):
pass

a = A()
a.items = [A(), A(), A()]
a.first = a.items[0]
a.stuff = {a.first: a.first}
a.morestuff = {a.stuff: a.stuff}

pickle = jsonpickle.encode(a)
b = jsonpickle.decode(pickle)

item = b.items[0]
self.assertEqual(b.first, item)
self.assertEqual(b.stuff[b.first], item)
self.assertEqual(b.morestuff[b.stuff][b.first], item)


John Paulett and I both keep jsonpickle repos on github:

http://github.com/johnpaulett/jsonpickle
http://github.com/davvid/jsonpickle


--
David

Reply all
Reply to author
Forward
0 new messages