Skip to content

feat(a2ui_message): make toJson compatible with fromJson#780

Open
matiasleyba wants to merge 1 commit intoflutter:mainfrom
matiasleyba:feat/a2ui-message-to-json
Open

feat(a2ui_message): make toJson compatible with fromJson#780
matiasleyba wants to merge 1 commit intoflutter:mainfrom
matiasleyba:feat/a2ui-message-to-json

Conversation

@matiasleyba
Copy link

@matiasleyba matiasleyba commented Mar 1, 2026

Description

  • Each A2uiMessage subclass’s toJson() now returns the wrapped envelope (version + one of createSurface / updateComponents / updateDataModel / deleteSurface) instead of a flat payload.
  • This matches the shape that A2uiMessage.fromJson() expects, so round-trip works.

Why

  • Use case: Persisting messages locally (e.g. saving conversation history) and reloading with A2uiMessage.fromJson(saved).
  • Previously, fromJson(message.toJson()) failed because the root map had no action key.
  • Before: To save a message you had to switch on each type (CreateSurface, UpdateComponents, etc.) and build JSON per variant.
    • Now: You can call message.toJson() on any A2uiMessage and save without type checks.

  • CreateSurface, UpdateComponents, UpdateDataModel, and DeleteSurface now put their payload under the corresponding key.

  • Round-trip tests were added

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-devrel channel on Discord.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the toJson() methods for A2uiMessage subclasses to make them compatible with A2uiMessage.fromJson(), enabling round-trip serialization. The changes are well-implemented and include corresponding updates to tests and new round-trip tests. My feedback focuses on improving maintainability by using constants for repeated string literals like the API version and JSON keys, and a minor cleanup in the new test code.

@matiasleyba matiasleyba force-pushed the feat/a2ui-message-to-json branch from c8c6d5b to 1e42529 Compare March 7, 2026 14:52
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.

1 participant