          elif hasattr(obj, '__getitem__'):
              cls = (list if isinstance(obj, (list, tuple)) else dict)
              try:
                  return cls(obj)
              except Exception:
                  pass
          elif hasattr(obj, '__iter__'):
              return tuple(item for item in obj)
          return super().default(obj)
 
</s> remove             try:
 </s> add             with contextlib.suppress(Exception): </s> remove         except TypeError:  # Input is an unhashable type
            pass
 </s> add  </s> remove         try:
 </s> add         with contextlib.suppress(TypeError): </s> remove             if input_format.lower() == ISO_8601:
                try:
 </s> add             with contextlib.suppress(ValueError, TypeError):
                if input_format.lower() == ISO_8601: </s> remove         try:
 </s> add         with contextlib.suppress(AttributeError, KeyError, ValueError):
          elif hasattr(obj, '__getitem__'):
              cls = (list if isinstance(obj, (list, tuple)) else dict)
              try:
                  return cls(obj)


          elif hasattr(obj, '__iter__'):
              return tuple(item for item in obj)
          return super().default(obj)
keep keep keep keep replace replace keep keep keep
 Refactor: Replace try/except with contextlib.suppress() (#8676) 
rest_framework/utils/encoders.py