code: def json_encode(obj, serialize):
      
      if hasattr(obj, 'to_dict'):
          return obj.to_dict(serialize=serialize)
      elif isinstance(obj, datetime):
          return obj.date().isoformat()
      elif isinstance(obj, date):
          return obj.isoformat()
      elif isinstance(obj, ProxyDict):
          return dict(obj)
      elif isinstance(obj, ProxyList):
          return list(obj)
      elif is_iterable_but_not_string(obj):
          return list(obj)
docs: Handle encoding complex types.