Storing instances using jsonpickle

Ned Batchelder ned at nedbatchelder.com
Wed Sep 3 22:52:50 CEST 2014


On 9/3/14 4:32 PM, Josh English wrote:
> I am using jsonpickle to store instances of an object into separate data files.
>
> If I make any changes to the original class definition of the object, when I recreate my stored instances, they are recreated using the original class definition, so any new attributes, methods, or properties, are lost.
>
> I think this is happening because JSON is internalizing the class definition, ignoring the updates. Is this true? Is it possible to refresh JSON's knowledge of a class?
>

Pickle (and it looks like jsonpickle) does not invoke the class' 
__init__ method when it reconstitutes objects.  Your new __init__ is not 
being run, so new attributes it defines are not being created.

This is one of the reasons that people avoid pickle: being completely 
implicit is very handy, but also fragile.

-- 
Ned Batchelder, http://nedbatchelder.com




More information about the Python-list mailing list