The encoding is basically string representation of a dictionary, containing the object's fields. However, a dictionary does not respect order, and I could potentially get different encoding string on different runs. How do I preclude this from happening? Or should I use another library where I can ensure deterministic encoding?
By deterministic encoding, I mean if I create 100000 objects that are practically the same, i.e. same class and same constructor args, when I call encode()
on each one of them, I get the exact same string every time.
So, for example, if I have
class MyClass(object):
def __init__(self, a, b):
self.a = a
self.b = b
c1 = MyClass(1, 2)
c2 = MyClass(1, 2)
I want to be sure that the strings encode(c1) and encode(c2) are perfectly identical, character for character, i.e.
assert jsonpickle.encode(c1)==jsonpickle.encode(c2)