I am trying to serialize complex python object with multiple nested objects and lists. Problem I encountered is described here: Python serialize objects list to JSON
Now, I have some objects, lets say:
class A:
id = 0
objects_b = []
objects_c = []
class B:
id = 0
class C:
id = 0
a = A()
b = B()
c = C()
a.objects_b = [b]
a.objects_c = [c]
I don't want to add custom methods to each new class I add to my structure. Is there any way to make unified serialization method that will handle each new class no matter how is it included, in a list or as a parameter? Method that will use any object type would be great, but I could tolerate subclassing all my objects from some general type too. Trying to figure it for last hour and going a little crazy, I am almost ready to create my own serialization method without using json lib, but thats seems too much...
json, why not usepickle? That is part of the standard library and it should handle custom Python types.dictandlistwithstrandinttype fields/values. It sounds like you don't want JSON, you wantpickle.