code: def component_to_dict(obj: Any) -> Dict[str, Any]:
      """
      The marshaller used by the Pipeline. If a `to_dict` method is present in the
      component instance, that will be used instead of the default method.
      """
      if hasattr(obj, "to_dict"):
          return obj.to_dict()
  
      init_parameters = {}
      for name, param in inspect.signature(
          obj.__init__
      ).parameters.items():
          # Ignore `args` and `kwargs`, used by the default constructor
          if name in ("args", "kwargs"):
              continue
          try:
              # This only works if the Component constructor assigns the init
              # parameter to an instance variable or property with the same name
              param_value = getattr(obj, name)
          except AttributeError as e:
              # If the parameter doesn't have a default value, raise an error
              if param.default is param.empty:
                  raise SerializationError(
                      f"Cannot determine the value of the init parameter '{name}' for the class {obj.__class__.__name__}."
                      f"You can fix this error by assigning 'self.{name} = {name}' or adding a "
                      f"custom serialization method 'to_dict' to the class."
                  ) from e
              # In case the init parameter was not assigned, we use the default value
              param_value = param.default
          init_parameters[name] = param_value
  
      return default_to_dict(obj, **init_parameters)
  
imports: import inspect
  from typing import Type, Dict, Any
  from haystack.core.errors import DeserializationError, SerializationError
label_desc: Use image node_id 1 for calling a global function with example usage: component_to_dict(obj) and returns: default_to_dict, obj