Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ public void tearDown() {
public void testListTasksWithDefaultBuilder() throws Exception {
JsonObject params = listTasksAndGetRequestParams(ListTasksParams.builder().build());

assertEquals("", params.get("tenant").getAsString());
assertFalse(params.has("tenant"));
}

@Test
public void testListTasksWithDefaultConstructor() throws Exception {
JsonObject params = listTasksAndGetRequestParams(new ListTasksParams());

assertEquals("", params.get("tenant").getAsString());
assertFalse(params.has("tenant"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ public class JsonMessages {
"configuration":{
"acceptedOutputModes":[
"text"
],
"returnImmediately":false
]
},
"metadata":{

Expand Down Expand Up @@ -200,8 +199,7 @@ public class JsonMessages {
"configuration":{
"acceptedOutputModes":[
"text"
],
"returnImmediately":false
]
},
"metadata":{

Expand Down Expand Up @@ -384,8 +382,7 @@ public class JsonMessages {
"configuration":{
"acceptedOutputModes":[
"text"
],
"returnImmediately":false
]
},
"metadata":{

Expand Down Expand Up @@ -451,8 +448,7 @@ public class JsonMessages {
"configuration":{
"acceptedOutputModes":[
"text"
],
"returnImmediately":false
]
},
"metadata":{

Expand Down Expand Up @@ -522,8 +518,7 @@ public class JsonMessages {
"configuration":{
"acceptedOutputModes":[
"text"
],
"returnImmediately":false
]
},
"metadata":{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,9 @@ public static String toJsonRPCRequest(@Nullable String requestId, String method,
output.name("method").value(method);
}
if (payload != null) {
// Unlike responses, omit unset fields: receivers may treat "taskId": "" as a real value
String resultValue = ProtoJsonUtils.toJson(
JsonFormat.printer().alwaysPrintFieldsWithNoPresence().omittingInsignificantWhitespace(), payload);
JsonFormat.printer().omittingInsignificantWhitespace(), payload);
output.name("params").jsonValue(resultValue);
}
output.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,32 @@ public void testToJsonRPCRequest_doesNotHtmlEscapeAngleBrackets() {
"JSON must not contain HTML-escaped '>' (\\u003e) but got: " + json);
}

@Test
public void testToJsonRPCRequest_omitsUnsetFields() throws JsonProcessingException {
// Issue #770: unset taskId, contextId and tenant were sent as empty strings
MessageSendParams params = new MessageSendParams(
Message.builder()
.role(Message.Role.ROLE_USER)
.parts(Collections.singletonList(new TextPart("hello")))
.messageId("message-1234")
.build(),
null, null
);

String json = JSONRPCUtils.toJsonRPCRequest("test-id", SEND_MESSAGE_METHOD,
ProtoUtils.ToProto.sendMessageRequest(params));

JsonObject requestParams = JsonParser.parseString(json).getAsJsonObject().getAsJsonObject("params");
assertFalse(requestParams.has("tenant"), json);
JsonObject message = requestParams.getAsJsonObject("message");
assertFalse(message.has("taskId"), json);
assertFalse(message.has("contextId"), json);
Message parsed = assertInstanceOf(SendMessageRequest.class, JSONRPCUtils.parseRequestBody(json, null))
.getParams().message();
assertNull(parsed.taskId());
assertNull(parsed.contextId());
}

@Test
public void testToJsonRPCResultResponse_doesNotHtmlEscapeAngleBrackets() {
// Reproduce issue #892: server responses must also send literal angle brackets.
Expand Down
Loading