Skip to content
Open
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 @@ -93,10 +93,7 @@ public class JsonMessages {
{
"text":"tell me a joke"
}
],
"metadata":{

}
]
}
}
}""";
Expand Down Expand Up @@ -143,18 +140,12 @@ public class JsonMessages {
{
"text":"tell me a joke"
}
],
"metadata":{
}
]
},
"configuration":{
"acceptedOutputModes":[
"text"
],
"returnImmediately":false
},
"metadata":{

]
}
}
}""";
Expand Down Expand Up @@ -192,19 +183,12 @@ public class JsonMessages {
{
"text":"tell me a joke"
}
],
"metadata":{

}
]
},
"configuration":{
"acceptedOutputModes":[
"text"
],
"returnImmediately":false
},
"metadata":{

]
}
}
}""";
Expand Down Expand Up @@ -376,19 +360,12 @@ public class JsonMessages {
"url":"file:///path/to/image.jpg",
"mediaType":"image/jpeg"
}
],
"metadata":{

}
]
},
"configuration":{
"acceptedOutputModes":[
"text"
],
"returnImmediately":false
},
"metadata":{

]
}
}
}""";
Expand Down Expand Up @@ -443,19 +420,12 @@ public class JsonMessages {
"timestamp":"2024-01-15T10:30:00Z"
}
}
],
"metadata":{

}
]
},
"configuration":{
"acceptedOutputModes":[
"text"
],
"returnImmediately":false
},
"metadata":{

]
}
}
}""";
Expand Down Expand Up @@ -514,19 +484,12 @@ public class JsonMessages {
"labels":["Q1", "Q2", "Q3", "Q4"]
}
}
],
"metadata":{

}
]
},
"configuration":{
"acceptedOutputModes":[
"text"
],
"returnImmediately":false
},
"metadata":{

]
}
}
}""";
Expand Down
7 changes: 5 additions & 2 deletions spec-grpc/src/main/java/io/a2a/grpc/utils/JSONRPCUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ public class JSONRPCUtils {
private static final Pattern EXTRACT_WRONG_TYPE = Pattern.compile("Expected (.*) but found \".*\"");
static final String ERROR_MESSAGE = "Invalid request content: %s. Please verify the request matches the expected schema for this method.";

private static final JsonFormat.Printer REQUEST_PRINTER = JsonFormat.printer().omittingInsignificantWhitespace();
private static final JsonFormat.Printer RESPONSE_PRINTER = JsonFormat.printer().alwaysPrintFieldsWithNoPresence().omittingInsignificantWhitespace();

public static A2ARequest<?> parseRequestBody(String body, @Nullable String tenant) throws JsonMappingException, JsonProcessingException {
JsonElement jelement = JsonParser.parseString(body);
JsonObject jsonRpc = jelement.getAsJsonObject();
Expand Down Expand Up @@ -556,7 +559,7 @@ public static String toJsonRPCRequest(@Nullable String requestId, String method,
output.name("method").value(method);
}
if (payload != null) {
String resultValue = JsonFormat.printer().alwaysPrintFieldsWithNoPresence().omittingInsignificantWhitespace().print(payload);
String resultValue = REQUEST_PRINTER.print(payload);
output.name("params").jsonValue(resultValue);
}
output.endObject();
Expand All @@ -579,7 +582,7 @@ public static String toJsonRPCResultResponse(Object requestId, com.google.protob
output.name("id").value(number.longValue());
}
}
String resultValue = JsonFormat.printer().alwaysPrintFieldsWithNoPresence().omittingInsignificantWhitespace().print(builder);
String resultValue = RESPONSE_PRINTER.print(builder);
output.name("result").jsonValue(resultValue);
output.endObject();
return result.toString();
Expand Down
Loading