@@ -268,6 +268,20 @@ def test_serializes_named_tuple(self) -> None:
268268 assert isinstance (parsed ["point" ], list )
269269 assert parsed ["point" ] == [10 , 20 ]
270270
271+ def test_serializes_object_with_as_dict (self ) -> None :
272+ """Test object with as_dict property via json.dumps."""
273+
274+ class RuntimeLike :
275+ @property
276+ def as_dict (self ) -> dict [str , Any ]:
277+ return {"host" : "localhost" , "port" : 8080 }
278+
279+ obj = RuntimeLike ()
280+ data = {"runtime" : obj }
281+ result = serialize_json (data )
282+ parsed = json .loads (result )
283+ assert parsed ["runtime" ] == {"host" : "localhost" , "port" : 8080 }
284+
271285 def test_serializes_object_with_to_dict (self ) -> None :
272286 """Test object with to_dict method via json.dumps."""
273287
@@ -294,6 +308,14 @@ def __str__(self) -> str:
294308 parsed = json .loads (result )
295309 assert parsed ["obj" ] == "custom_string"
296310
311+ def test_serializes_exception (self ) -> None :
312+ """Test Exception serialization via json.dumps."""
313+ err = ValueError ("something went wrong" )
314+ data = {"error" : err }
315+ result = serialize_json (data )
316+ parsed = json .loads (result )
317+ assert parsed ["error" ] == "something went wrong"
318+
297319 def test_with_json_dumps (self ) -> None :
298320 """Test integration with json.dumps()."""
299321
@@ -325,6 +347,7 @@ def test_with_json_dumps_complex_nested(self) -> None:
325347 "datetime" : datetime (2024 , 1 , 1 ),
326348 "set" : {1 , 2 , 3 },
327349 "tuple" : (4 , 5 , 6 ),
350+ "error" : ValueError ("something failed" ),
328351 }
329352
330353 result = serialize_json (data )
@@ -336,6 +359,7 @@ def test_with_json_dumps_complex_nested(self) -> None:
336359 assert "2024-01-01" in parsed ["datetime" ]
337360 assert set (parsed ["set" ]) == {1 , 2 , 3 }
338361 assert parsed ["tuple" ] == [4 , 5 , 6 ]
362+ assert parsed ["error" ] == "something failed"
339363
340364 def test_with_list_of_pydantic_models (self ) -> None :
341365 """Test with list of Pydantic models (common MCP scenario)."""
0 commit comments