jsonpickle/jsonpickle — Issue #21: Simple round-trip fails to reconstruct object of locally-defined class
Author: Kylotan
Created: 2011-10-31 19:19:08+00:00
State: open

The following unit test, inside a function, triggers the first assertion (or will trigger the second if the 1st is removed)

def test_json_stuff(self):
import jsonpickle
class SomeObject(object):
pass
object_original = SomeObject()
object_clone = jsonpickle.decode(jsonpickle.encode(object_original))
self.assertFalse(isinstance(object_clone, type(dict())))
self.assert_(isinstance(object_clone, SomeObject))

Traceback (most recent call last):
File "test.py", line 248, in test_json_stuff
self.assertFalse(isinstance(object_clone, type(dict())))
AssertionError

Basically it's returning the plain dict instead of reconstructing the object as expected. However, if the definition of the 'SomeObject' class is moved to file scope, it works.

The worst bit about this is not the limitation, but the silent failure and the returning of the dict instead of raising an exception.