@@ -156,3 +156,39 @@ def serialize_json(obj: Any) -> str:
156156 '{"name": "Review PR", "created": "2024-01-15T10:30:00"}'
157157 """
158158 return json .dumps (obj , default = serialize_defaults )
159+
160+ def serialize_object (obj ):
161+ """Recursively serializes an object and all its nested components."""
162+ # Handle Pydantic models
163+ if hasattr (obj , "model_dump" ):
164+ return serialize_object (obj .model_dump (by_alias = True ))
165+ elif hasattr (obj , "dict" ):
166+ return serialize_object (obj .dict ())
167+ elif hasattr (obj , "to_dict" ):
168+ return serialize_object (obj .to_dict ())
169+ # Special handling for UiPathBaseRuntimeErrors
170+ elif hasattr (obj , "as_dict" ):
171+ return serialize_object (obj .as_dict )
172+ elif isinstance (obj , (datetime , date , time )):
173+ return obj .isoformat ()
174+ # Handle dictionaries
175+ elif isinstance (obj , dict ):
176+ return {k : serialize_object (v ) for k , v in obj .items ()}
177+ # Handle lists
178+ elif isinstance (obj , list ):
179+ return [serialize_object (item ) for item in obj ]
180+ # Handle exceptions
181+ elif isinstance (obj , Exception ):
182+ return str (obj )
183+ # Handle other iterable objects (convert to dict first)
184+ elif hasattr (obj , "__iter__" ) and not isinstance (obj , (str , bytes )):
185+ try :
186+ return serialize_object (dict (obj ))
187+ except (TypeError , ValueError ):
188+ return obj
189+ # UUIDs must be serialized explicitly
190+ elif isinstance (obj , uuid .UUID ):
191+ return str (obj )
192+ # Return primitive types as is
193+ else :
194+ return obj
0 commit comments