I've read through a few questions that address something similar, but wanted to ask about this.
I have two Python classes, simplified here:
class Service:
def __init__(self):
self.ServiceName = None
self.ServiceExpDate = None
class Provision:
def __init__(self):
self.ID = None
self.Type = None
self.Services = [] # a list of Service objects
When I go to JSON encode an instance of the Provision class:
jsonProvision = json.dumps(provision.__dict__)
I get the correct output if I don't have any Services, but if it tries to serialize the Service class I get:
TypeError: <common.Service instance at 0x123d7e8> is not JSON serializable
Do I need to write a JSON encoder to handle this directly, or is there a better way to serialize the Service class?
Thanks!