Skip to content

fix!: Remove includingDefaultValueFields() from JsonFormat.printer() in JSONRPCUtils#692

Open
CokeLee777 wants to merge 1 commit intoa2aproject:mainfrom
CokeLee777:issue-689
Open

fix!: Remove includingDefaultValueFields() from JsonFormat.printer() in JSONRPCUtils#692
CokeLee777 wants to merge 1 commit intoa2aproject:mainfrom
CokeLee777:issue-689

Conversation

@CokeLee777
Copy link
Contributor

Description

Remove the includingDefaultValueFields() call from JsonFormat.printer() in toJsonRPCRequest and toJsonRPCResultResponse methods to prevent unset protobuf fields (e.g. filename, mediaType, metadata) from being emitted as default values in the serialized JSON output.

Add tests to verify that a TextPart with no metadata serializes with only the text field present, and that optional fields such as filename, mediaType, and metadata are excluded when not explicitly set.

Fixes #689

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where protobuf fields with default values were being unnecessarily included in the JSON output, leading to verbose and potentially misleading serialization. By adjusting the JSON formatting configuration, the change ensures that only explicitly set fields are present in the serialized JSON, improving data clarity and reducing payload size. The accompanying tests validate this corrected behavior, particularly for optional fields within message parts.

Highlights

  • JSON Serialization Fix: Removed the includingDefaultValueFields() option from JsonFormat.printer() calls in toJsonRPCRequest and toJsonRPCResultResponse methods. This prevents unset protobuf fields from being serialized with their default values, ensuring cleaner and more accurate JSON output.
  • New Test Coverage: Added new unit tests to JSONRPCUtilsTest to explicitly verify that optional protobuf fields, such as filename, mediaType, and metadata, are correctly omitted from the JSON output when they are not explicitly set in TextPart messages.
Changelog
  • spec-grpc/src/main/java/io/a2a/grpc/utils/JSONRPCUtils.java
    • Removed includingDefaultValueFields() from JsonFormat.printer() when serializing toJsonRPCRequest payloads.
    • Removed includingDefaultValueFields() from JsonFormat.printer() when serializing toJsonRPCResultResponse results.
  • spec-grpc/src/test/java/io/a2a/grpc/utils/JSONRPCUtilsTest.java
    • Added new test cases to verify that TextPart messages with null or unset metadata correctly serialize with only the text field.
    • Added new test cases to verify that TextPart messages with metadata correctly serialize with only text and metadata fields, omitting other optional fields.
    • Refactored import statements for better organization.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 correctly addresses the issue of default protobuf field values being serialized into JSON by removing the includingDefaultValueFields() call. The changes in JSONRPCUtils.java are correct, and the accompanying tests in JSONRPCUtilsTest.java effectively verify the fix. I have a suggestion to improve the test code's maintainability.

…n JSONRPCUtils

Remove the `includingDefaultValueFields()` call from `JsonFormat.printer()`
in `toJsonRPCRequest` and `toJsonRPCResultResponse` methods to prevent
unset protobuf fields (e.g. `filename`, `mediaType`, `metadata`) from being
emitted as default values in the serialized JSON output.

Add tests to verify that a `TextPart` with no metadata serializes with only
the `text` field present, and that optional fields such as `filename`,
`mediaType`, and `metadata` are excluded when not explicitly set.

Fixes a2aproject#689
@CokeLee777
Copy link
Contributor Author

/gemini review

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 correctly addresses the issue of serializing default protobuf field values by removing includingDefaultValueFields() from the JsonFormat.printer(). The change is applied to both toJsonRPCRequest and toJsonRPCResultResponse methods, which is the correct approach. The new tests are well-structured and effectively verify that optional fields in TextPart (such as filename, mediaType, and metadata) are correctly omitted from the JSON output when they are not explicitly set, confirming the fix.

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]: RestHandler#sendMessage returns part with both "text" and "filename" fields

1 participant