If the method returns a value of Mono type, the calling effect cannot be achieved.
So the modifications are as follows:
public String convert(@Nullable Object result, @Nullable Type returnType) {
// This is the newly added filtering code used to obtain the real values in Mono
**if (result instanceof Mono<?>) {
result = ((Mono<?>) result).block();
}**
if (returnType == Void.TYPE) {
logger.debug("The tool has no return type. Converting to conventional response.");
return JsonParser.toJson("Done");
} else if (result instanceof RenderedImage) {
ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);
try {
ImageIO.write((RenderedImage)result, "PNG", buf);
} catch (IOException var5) {
return "Failed to convert tool result to a base64 image: " + var5.getMessage();
}
String imgB64 = Base64.getEncoder().encodeToString(buf.toByteArray());
return JsonParser.toJson(Map.of("mimeType", "image/png", "data", imgB64));
} else {
logger.debug("Converting tool result to JSON.");
return JsonParser.toJson(result);
}
}