code: def default(self, obj):
          
          if isinstance(obj, datetime):
              return obj.isoformat()
  
          if issubclass(obj.__class__, Enum.__class__):
              return obj.value
  
          to_json = getattr(obj, 'to_json', None)
          if to_json:
              out = obj.to_json()
              if issubclass(obj.__class__, Model):
                  out.update({'__type': obj.__class__.__name__})
  
              return out
  
          return JSONEncoder.default(self, obj)
docs: Default object encoder function
  
          Args:
              obj (:obj:`Any`): Object to be serialized
  
          Returns:
              JSON string