Skip to content

Commit c5c4c3b

Browse files
committed
fix: omit optional fields with default values from client JSON serialization
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
1 parent d1578d3 commit c5c4c3b

2 files changed

Lines changed: 12 additions & 49 deletions

File tree

client/transport/jsonrpc/src/test/java/io/a2a/client/transport/jsonrpc/JsonMessages.java

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ public class JsonMessages {
9393
{
9494
"text":"tell me a joke"
9595
}
96-
],
97-
"metadata":{
98-
99-
}
96+
]
10097
}
10198
}
10299
}""";
@@ -143,18 +140,12 @@ public class JsonMessages {
143140
{
144141
"text":"tell me a joke"
145142
}
146-
],
147-
"metadata":{
148-
}
143+
]
149144
},
150145
"configuration":{
151146
"acceptedOutputModes":[
152147
"text"
153-
],
154-
"returnImmediately":false
155-
},
156-
"metadata":{
157-
148+
]
158149
}
159150
}
160151
}""";
@@ -192,19 +183,12 @@ public class JsonMessages {
192183
{
193184
"text":"tell me a joke"
194185
}
195-
],
196-
"metadata":{
197-
198-
}
186+
]
199187
},
200188
"configuration":{
201189
"acceptedOutputModes":[
202190
"text"
203-
],
204-
"returnImmediately":false
205-
},
206-
"metadata":{
207-
191+
]
208192
}
209193
}
210194
}""";
@@ -376,19 +360,12 @@ public class JsonMessages {
376360
"url":"file:///path/to/image.jpg",
377361
"mediaType":"image/jpeg"
378362
}
379-
],
380-
"metadata":{
381-
382-
}
363+
]
383364
},
384365
"configuration":{
385366
"acceptedOutputModes":[
386367
"text"
387-
],
388-
"returnImmediately":false
389-
},
390-
"metadata":{
391-
368+
]
392369
}
393370
}
394371
}""";
@@ -443,19 +420,12 @@ public class JsonMessages {
443420
"timestamp":"2024-01-15T10:30:00Z"
444421
}
445422
}
446-
],
447-
"metadata":{
448-
449-
}
423+
]
450424
},
451425
"configuration":{
452426
"acceptedOutputModes":[
453427
"text"
454-
],
455-
"returnImmediately":false
456-
},
457-
"metadata":{
458-
428+
]
459429
}
460430
}
461431
}""";
@@ -514,19 +484,12 @@ public class JsonMessages {
514484
"labels":["Q1", "Q2", "Q3", "Q4"]
515485
}
516486
}
517-
],
518-
"metadata":{
519-
520-
}
487+
]
521488
},
522489
"configuration":{
523490
"acceptedOutputModes":[
524491
"text"
525-
],
526-
"returnImmediately":false
527-
},
528-
"metadata":{
529-
492+
]
530493
}
531494
}
532495
}""";

spec-grpc/src/main/java/io/a2a/grpc/utils/JSONRPCUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public static String toJsonRPCRequest(@Nullable String requestId, String method,
556556
output.name("method").value(method);
557557
}
558558
if (payload != null) {
559-
String resultValue = JsonFormat.printer().alwaysPrintFieldsWithNoPresence().omittingInsignificantWhitespace().print(payload);
559+
String resultValue = JsonFormat.printer().omittingInsignificantWhitespace().print(payload);
560560
output.name("params").jsonValue(resultValue);
561561
}
562562
output.endObject();

0 commit comments

Comments
 (0)