I wonder why the jsonpickle-module when consecutively applying or calling encode & decode does not pass the isinstance(...) check in Python 3.8.
Let say i have a simple class Person.
Here some code to illustrate what i mean:
import jsonpickle
class Person:
id: int = -1
name: str = "John Doe"
def __init__(self, pId: int = None, name: str = None) -> None:
self.id = (pId, self.id)[pId is None]
self.name = (name, self.name)[name is None]
testInstance = Person()
testInstanceJSON = jsonpickle.encode(testInstance, unpicklable=True, make_refs=True)
print(testInstanceJSON)
testInstanceObject = jsonpickle.decode(testInstanceJSON)
print(testInstanceObject)
print(isinstance(testInstanceObject, Person.__class__))
It returns False on the last print-command!
The attribute
__class__of an object provides the class the object is an instance of.Classes like
Personare also objects and instances oftype.This means that
is the same as
but of course
testInstanceObjectis not an instance oftype.Change it to
to check if
testInstanceObjectis an instance ofPerson.