Skip to content

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

Open
enjoykumawat wants to merge 3 commits intogoogle:mainfrom
enjoykumawat:fix/a2a-serialize-value-types
Open

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

Conversation

@enjoykumawat
Copy link
Copy Markdown
Contributor

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

@rohityan rohityan self-assigned this Apr 9, 2026
@enjoykumawat enjoykumawat force-pushed the fix/a2a-serialize-value-types branch from d162c0c to 5070c05 Compare April 9, 2026 07:39
@rohityan rohityan added a2a [Component] This issue is related a2a support inside ADK. needs review [Status] The PR/issue is awaiting review from the maintainer labels Apr 13, 2026
@rohityan
Copy link
Copy Markdown
Collaborator

Hi @enjoykumawat , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share.

@rohityan
Copy link
Copy Markdown
Collaborator

Hi @DeanChensj , can you please review this.

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

Labels

a2a [Component] This issue is related a2a support inside ADK. needs review [Status] The PR/issue is awaiting review from the maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants