Skip to content

fix: omit optional fields with default values from client JSON serialization#774

Open
jmesnil wants to merge 1 commit intoa2aproject:mainfrom
jmesnil:770_omit_default_fields
Open

fix: omit optional fields with default values from client JSON serialization#774
jmesnil wants to merge 1 commit intoa2aproject:mainfrom
jmesnil:770_omit_default_fields

Conversation

@jmesnil
Copy link
Copy Markdown
Collaborator

@jmesnil jmesnil commented Mar 27, 2026

The JSON-RPC client serialization used alwaysPrintFieldsWithNoPresence() which caused proto3 implicit-presence fields (taskId, contextId, tenant, etc.) to be serialized as empty strings instead of being omitted.

Removed alwaysPrintFieldsWithNoPresence() from JsonFormat.printer() in JSONRPCUtils.toJsonRPCRequest() (client requests only), aligning with the REST client transport which already omitted it.

This fixes #770

Copy link
Copy Markdown
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 JSON serialization in JSONRPCUtils.java by removing the alwaysPrintFieldsWithNoPresence() configuration, which results in more compact JSON output. Correspondingly, several test cases in JsonMessages.java were updated to remove empty metadata objects and default boolean fields. Feedback suggests optimizing performance by defining JsonFormat.Printer instances as static final constants to avoid redundant object creation during serialization.

…ization

The JSON-RPC client serialization used alwaysPrintFieldsWithNoPresence()
which caused proto3 implicit-presence fields (taskId, contextId, tenant, etc.)
to be serialized as empty strings instead of being omitted.

Removed alwaysPrintFieldsWithNoPresence() from JsonFormat.printer() in
JSONRPCUtils.toJsonRPCRequest() (client requests only), aligning with the
REST client transport which already omitted it.

This fixes a2aproject#770
@jmesnil jmesnil force-pushed the 770_omit_default_fields branch from c5c4c3b to 47dc31b Compare March 27, 2026 08:32
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.

[Bug]: a2a-java client sends message with empty task ID and context ID

1 participant