fix: omit optional fields with default values from client JSON serialization - #774
fix: omit optional fields with default values from client JSON serialization#774jmesnil wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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
c5c4c3b to
47dc31b
Compare
|
Verified against current Root cause confirmed. On
Because proto3 scalar fields use implicit presence, One scope note on the current diff: it changes only the request printer and leaves the response printer emitting empty scalars. That is a defensible split (this PR targets what the client sends, per the title), but the same absent-versus-empty hazard applies to Merge state: For grounding, this absent-is-not-empty rule is one we hold on our own signing and canonicalisation paths, so the concern is not theoretical for us: optional fields are omitted from the preimage rather than emitted empty, because an empty placeholder changes the bytes that get signed and verified. Thanks for chasing this down to the printer; the diagnosis is right and the fix is the minimal correct one once rebased. |
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