code: def default_to_dict(obj: Any, **init_parameters) -> Dict[str, Any]:
      """
      Utility function to serialize an object to a dictionary.
      This is mostly necessary for Components but it can be used by any object.
  
      `init_parameters` are parameters passed to the object class `__init__`.
      They must be defined explicitly as they'll be used when creating a new
      instance of `obj` with `from_dict`. Omitting them might cause deserialisation
      errors or unexpected behaviours later, when calling `from_dict`.
  
      An example usage:
  
      ```python
      class MyClass:
          def __init__(self, my_param: int = 10):
              self.my_param = my_param
  
          def to_dict(self):
              return default_to_dict(self, my_param=self.my_param)
  
  
      obj = MyClass(my_param=1000)
      data = obj.to_dict()
      assert data == {
          "type": "MyClass",
          "init_parameters": {
              "my_param": 1000,
          },
      }
      ```
      """
      return {
          "type": f"{obj.__class__.__module__}.{obj.__class__.__name__}",
          "init_parameters": init_parameters,
      }
  
imports: import inspect
  from typing import Type, Dict, Any
  from haystack.core.errors import DeserializationError, SerializationError
label_desc: Use image node_id 3 for calling a global function with example usage: default_to_dict(obj) and returns: dict