-
Notifications
You must be signed in to change notification settings - Fork 105
fix: Fix Security JSON serialization #592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Fix Security JSON serialization #592
Conversation
This ensures that the JSON representation of the Agent card is the same wether coming from the JSON-RPC endpoint or the REST one. This fixes a2aproject#591 Signed-off-by: Jeff Mesnil <jmesnil@ibm.com>
Summary of ChangesHello @jmesnil, 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 introduces significant improvements to JSON serialization within the system, primarily focusing on the SecurityScheme hierarchy and the AgentCard endpoint. By implementing custom Gson TypeAdapter's and standardizing type identification, it resolves issues related to polymorphic serialization and ensures consistent and correct JSON output for security-related objects and the agent configuration. The changes also streamline existing serialization logic for Part and StreamingEventKind objects. Highlights
Using Gemini Code AssistThe 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
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 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
|
|
/gemini review |
There was a problem hiding this 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 introduces a custom GSON TypeAdapter for SecurityScheme to correctly handle polymorphic JSON serialization and deserialization, which is a solid approach. The changes also improve maintainability by replacing magic strings with constants. I've identified a few areas for improvement, including an unused import, a missing @SuppressWarnings that could lead to build warnings, and an opportunity to enhance performance and clarity by using a static constant. Additionally, there's a minor naming inconsistency in one of the security scheme types that could be addressed for better code uniformity. Overall, the changes are well-implemented and effectively address the serialization issue.
jsonrpc-common/src/main/java/io/a2a/jsonrpc/common/json/JsonUtil.java
Outdated
Show resolved
Hide resolved
jsonrpc-common/src/main/java/io/a2a/jsonrpc/common/json/JsonUtil.java
Outdated
Show resolved
Hide resolved
jsonrpc-common/src/main/java/io/a2a/jsonrpc/common/json/JsonUtil.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 effectively addresses the JSON serialization issues for SecurityScheme by implementing a custom GSON TypeAdapter. The changes are well-executed, including updating the SecurityScheme hierarchy with a type() discriminator, renaming constants for better clarity, and refactoring other type adapters for improved maintainability. Additionally, enforcing GSON for the agent card endpoint ensures consistent serialization behavior. I've included a couple of suggestions to enhance the robustness of the new and existing type adapters by making the parsing logic stricter.
jsonrpc-common/src/main/java/io/a2a/jsonrpc/common/json/JsonUtil.java
Outdated
Show resolved
Hide resolved
be0a9d6 to
77e3e3b
Compare
|
/gemini review |
There was a problem hiding this 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 effectively addresses the JSON serialization issue for SecurityScheme objects by introducing a custom GSON TypeAdapter for polymorphic handling. The changes are well-structured, introducing a type() discriminator in the SecurityScheme hierarchy and updating related code and tests. I've provided a few suggestions to improve consistency and robustness, particularly regarding the naming of a type identifier and the initialization of a delegate GSON instance. Overall, this is a solid fix.
jsonrpc-common/src/main/java/io/a2a/jsonrpc/common/json/JsonUtil.java
Outdated
Show resolved
Hide resolved
jsonrpc-common/src/main/java/io/a2a/jsonrpc/common/json/JsonUtil.java
Outdated
Show resolved
Hide resolved
77e3e3b to
b4accd5
Compare
|
/gemini review |
There was a problem hiding this 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 introduces a robust JSON serialization mechanism for SecurityScheme and other polymorphic types by leveraging custom Gson TypeAdapters. The changes are a significant improvement in correctness and maintainability. Key enhancements include implementing polymorphic serialization for the SecurityScheme hierarchy, adding a custom adapter for APIKeySecurityScheme.Location enums, and refactoring existing adapters for better robustness. My review identifies two high-severity issues related to missing null checks in the new TypeAdapter implementations, which could lead to NullPointerExceptions during serialization. With these fixes, the pull request will be in excellent shape.
b4accd5 to
97ee829
Compare
|
/gemini review |
There was a problem hiding this 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 effectively addresses the JSON serialization of SecurityScheme objects by introducing a custom TypeAdapter for polymorphic handling. The changes are well-structured, with updates to the spec to support the new type() discriminator, and refactoring in JsonUtil to use this new adapter. The simplifications in other type adapters are also a welcome improvement to maintainability. The overall implementation is robust and clean. I have one minor suggestion to restore a suppressed warning that was lost during refactoring.
043dec9 to
7aa6925
Compare
|
/gemini review |
There was a problem hiding this 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 effectively addresses the JSON serialization issues for SecurityScheme by introducing a custom SecuritySchemeTypeAdapter for polymorphic serialization with Gson. The changes are well-implemented across the board, from updating the SecurityScheme interface and its implementations to registering the new type adapter and ensuring its use in the agent card endpoint. The addition of SecuritySchemeSerializationTest provides good test coverage for the new serialization logic.
I've found one issue in JsonUtil.java regarding the initialization of a delegate Gson instance which could lead to serialization errors for FileContent. Please see the specific comment for details.
Overall, this is a solid fix that improves the robustness and correctness of JSON serialization in the project.
8b0e825 to
a0147aa
Compare
|
/gemini review |
There was a problem hiding this 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 effectively addresses JSON serialization issues for SecurityScheme by introducing a custom Gson TypeAdapter. The implementation is robust, handling polymorphic serialization and deserialization correctly. The changes also include beneficial refactorings in other type adapters, improving code quality and maintainability. The addition of a comprehensive test suite for SecurityScheme serialization is a great way to ensure the fix is working as expected and prevent future regressions. I have one suggestion to clean up unused imports in the new test file.
jsonrpc-common/src/test/java/io/a2a/jsonrpc/common/json/SecuritySchemeSerializationTest.java
Outdated
Show resolved
Hide resolved
Add an adapter for the SecurityScheme so that they are properly serialized in JSON with a single field identifying the type of the security scheme This fixes a2aproject#590 Signed-off-by: Jeff Mesnil <jmesnil@ibm.com>
Signed-off-by: Jeff Mesnil <jmesnil@ibm.com>
a0147aa to
90fb3de
Compare
|
/gemini summary |
Summary of ChangesThis pull request addresses and resolves several JSON serialization issues within the system, primarily focusing on the Highlights
Changelog
Activity
|
fix: Use GSON serialization for JSON-RPC Agent card endpoint
fix: Fix Security JSON serialization
Fixes #590 & #591