code: def default(self, obj):  # lint-amnesty, pylint: disable=arguments-differ, method-hidden
          
  
          if isinstance(obj, datetime):
              if obj.tzinfo is None:
                  # Localize to UTC naive datetime objects
                  obj = UTC.localize(obj)  # pylint: disable=no-value-for-parameter
              else:
                  # Convert to UTC datetime objects from other timezones
                  obj = obj.astimezone(UTC)
              return obj.isoformat()
          elif isinstance(obj, date):
              return obj.isoformat()
  
          return super(DateTimeJSONEncoder, self).default(obj)
docs: Serialize datetime and date objects of iso format.
  
          datatime objects are converted to UTC.