def serialize_object(self, attr, **kwargs):
        """Serialize a generic object.
        This will be handled as a dictionary. If object passed in is not
        a basic type (str, int, float, dict, list) it will simply be
        cast to str.

        :param dict attr: Object to be serialized.
        :rtype: dict or str
        """
        if attr is None:
            return None
        if isinstance(attr, ET.Element):
            return attr
        obj_type = type(attr)
        if obj_type in self.basic_types:
            return self.serialize_basic(attr, self.basic_types[obj_type], **kwargs)
        if obj_type is _long_type:
            return self.serialize_long(attr)
        if obj_type is unicode_str:
            return self.serialize_unicode(attr)
        if obj_type is datetime.datetime:
            return self.serialize_iso(attr)
        if obj_type is datetime.date:
            return self.serialize_date(attr)
        if obj_type is datetime.time:
            return self.serialize_time(attr)
        if obj_type is datetime.timedelta:
            return self.serialize_duration(attr)
        if obj_type is decimal.Decimal:
            return self.serialize_decimal(attr)

        # If it's a model or I know this dependency, serialize as a Model
        elif obj_type in self.dependencies.values() or isinstance(attr, Model):
            return self._serialize(attr)

        if obj_type == dict:
            serialized = {}
            for key, value in attr.items():
                try:
                    serialized[self.serialize_unicode(key)] = self.serialize_object(value, **kwargs)
                except ValueError:
                    serialized[self.serialize_unicode(key)] = None
            return serialized

        if obj_type == list:
            serialized = []
            for obj in attr:
                try:
                    serialized.append(self.serialize_object(obj, **kwargs))
                except ValueError:
                    pass
            return serialized
        return str(attr)
Serialize a generic object.
        This will be handled as a dictionary. If object passed in is not
        a basic type (str, int, float, dict, list) it will simply be
        cast to str.

        :param dict attr: Object to be serialized.
        :rtype: dict or str
        
Solutions/CyberArkAudit/Data Connectors/.python_packages/lib/site-packages/azure/monitor/ingestion/_serialization.py