Skip to content

fix: preserve JSON-native types in A2A _serialize_value()#5200

Open
enjoykumawat wants to merge 1 commit intogoogle:mainfrom
enjoykumawat:fix/a2a-serialize-value-types
Open

fix: preserve JSON-native types in A2A _serialize_value()#5200
enjoykumawat wants to merge 1 commit intogoogle:mainfrom
enjoykumawat:fix/a2a-serialize-value-types

Conversation

@enjoykumawat
Copy link
Copy Markdown

Summary

Fixes #5183

_serialize_value() in from_adk_event.py was calling str() on all non-Pydantic values, which corrupted JSON-native metadata types (dict, list, int, float, bool) by converting them to string representations.

Before: {"count": 42} became {"count": "42"}, {"tags": ["a","b"]} became {"tags": "['a', 'b']"}

After: JSON-native types (dict, list, int, float, bool, str) are passed through as-is. Only non-JSON-serializable types (e.g., datetime) are stringified.

Changes

  • src/google/adk/a2a/converters/from_adk_event.py: Added isinstance check for JSON-native types before the str() fallback in _serialize_value()
  • tests/unittests/a2a/converters/test_from_adk.py: Added TestSerializeValue class with tests for dict, list, int, float, bool, str, None, and non-JSON type handling

Test plan

  • All existing tests pass (pytest tests/unittests/a2a/converters/test_from_adk.py — 12 passed)
  • New tests verify each JSON-native type is preserved as-is
  • New test verifies non-JSON types (e.g., datetime) are still stringified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A2A _serialize_value() corrupts JSON-native metadata types to strings

1 participant