# Buggy code
def _process_object_types(self, vobj, level=0):
    """Serialize an object"""
    rdata = {}

    if vobj is None:
        rdata = None
    elif issubclass(type(vobj), str) or isinstance(vobj, str):
        rdata = vobj
    elif issubclass(type(vobj), bool) or isinstance(vobj, bool):
        rdata = vobj
    elif issubclass(type(vobj), int) or isinstance(vobj, int):
        rdata = vobj
    elif issubclass(type(vobj), float) or isinstance(vobj, float):
        rdata = vobj
    elif issubclass(type(vobj), long) or isinstance(vobj, long):
        rdata = vobj
    elif issubclass(type(vobj), list) or issubclass(type(vobj), tuple):
        rdata = []
        try:
            vobj = sorted(vobj)
        except Exception as e:
            pass
        for vi in vobj:
            if level + 1 <= self.maxlevel:
                # vid = self.facts_from_vobj(vi, level=(level+1))
                vid = self._process_object_types(vi, level=(level + 1))
                if vid:
                    rdata.append(vid)
    elif issubclass(type(vobj), dict):
        pass
    elif issubclass(type(vobj), object):
        methods = dir(vobj)
        methods = [str(x) for x in methods if not x.startswith("_")]
        methods = [x for x in methods if not x in self.bad_types]
        methods = sorted(methods)

        for method in methods:
            # Attempt to get the method, skip on fail
            try:
                methodToCall = getattr(vobj, method)
            except Exception as e:
                continue
            if callable(methodToCall):
                continue
            if self.lowerkeys:
                method = method.lower()
            if level + 1 <= self.maxlevel:
                rdata[method] = self._process_object_types(
                    methodToCall, level=(level + 1)
                )
    else:
        pass

    if not rdata:
        rdata = None
    return rdata


# Traceback (UnicodeDecodeError)
ansible/contrib/inventory/vmware_inventory.py
# few minutes here
Traceback (most recent call last):
File "ansible/contrib/inventory/vmware_inventory.py", line 552, in <module>
print(VMWareInventory().show())
File "ansible/contrib/inventory/vmware_inventory.py", line 109, in __init__
self.do_api_calls_update_cache()
File "ansible/contrib/inventory/vmware_inventory.py", line 155, in do_api_calls_update_cache
self.write_to_cache(self.inventory, self.cache_path_cache)
File "ansible/contrib/inventory/vmware_inventory.py", line 163, in write_to_cache
f.write(json.dumps(data))
File "/usr/lib/python2.7/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 201, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 264, in iterencode
return _iterencode(o, 0)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x99 in position 1: invalid start byte

# Fixed code
def _process_object_types(self, vobj, level=0):
    """Serialize an object"""
    rdata = {}

    if vobj is None:
        rdata = None
    elif issubclass(type(vobj), str) or isinstance(vobj, str):
        if vobj.isalnum():
            rdata = vobj
        else:
            rdata = vobj.decode("ascii", "ignore")
    elif issubclass(type(vobj), bool) or isinstance(vobj, bool):
        rdata = vobj
    elif issubclass(type(vobj), int) or isinstance(vobj, int):
        rdata = vobj
    elif issubclass(type(vobj), float) or isinstance(vobj, float):
        rdata = vobj
    elif issubclass(type(vobj), long) or isinstance(vobj, long):
        rdata = vobj
    elif issubclass(type(vobj), list) or issubclass(type(vobj), tuple):
        rdata = []
        try:
            vobj = sorted(vobj)
        except Exception as e:
            pass
        for vi in vobj:
            if level + 1 <= self.maxlevel:
                # vid = self.facts_from_vobj(vi, level=(level+1))
                vid = self._process_object_types(vi, level=(level + 1))
                if vid:
                    rdata.append(vid)
    elif issubclass(type(vobj), dict):
        pass
    elif issubclass(type(vobj), object):
        methods = dir(vobj)
        methods = [str(x) for x in methods if not x.startswith("_")]
        methods = [x for x in methods if not x in self.bad_types]
        methods = sorted(methods)

        for method in methods:
            # Attempt to get the method, skip on fail
            try:
                methodToCall = getattr(vobj, method)
            except Exception as e:
                continue
            if callable(methodToCall):
                continue
            if self.lowerkeys:
                method = method.lower()
            if level + 1 <= self.maxlevel:
                rdata[method] = self._process_object_types(
                    methodToCall, level=(level + 1)
                )
    else:
        pass

    if not rdata:
        rdata = None
    return rdata