'Serialize datetime and date objects of iso format.
datatime objects are converted to UTC.'

def default(self, obj):

    if isinstance(obj, datetime):
        if (obj.tzinfo is None):
            obj = UTC.localize(obj)
        else:
            obj = obj.astimezone(UTC)
        return obj.isoformat()
    elif isinstance(obj, date):
        return obj.isoformat()
    return super(DateTimeJSONEncoder, self).default(obj)
