我目前正在从 Java ASK-SDK v1 迁移到 Java ASK SDK v2 .
我尝试使用我构建响应的 ResponseBuilder 类返回 webhook 调用,并且数据是正确的,但是当我尝试使用 JSON 文本填充 HTTP 正文时, ResponseBuilder.toString()
值不仅仅使用字符串填充数据,我得到以下内容:
Optional[class Response {
outputSpeech: class SsmlOutputSpeech {
class OutputSpeech {
type: SSML
playBehavior: null
}
ssml: <speak>Some of the things you can say are What would you like to do?</speak>
}
card: null
reprompt: class Reprompt {
outputSpeech: class SsmlOutputSpeech {
class OutputSpeech {
type: SSML
playBehavior: null
}
ssml: <speak>You can say ..., is that what you want?</speak>
}
}
directives: []
shouldEndSession: false
canFulfillIntent: null
}]
是否有另一种方法来获取响应正文的字符串? BaseSkillResponse有一个 getResponse() 调用,但是,我无法弄清楚如何使用该类生成字符串响应输出。
最佳答案
我能够在我的类(class)中获取具有以下内容的字符串:
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
myFunction(){
try{
return toJsonString(responseBuilder.build().get());
} catch(IOException e) {
e.printStackTrace();
}
}
public String toJsonString(Response response)throws IOException {
return OBJECT_MAPPER.writeValueAsString(response);
}
关于java - ResponseBuilder toString() 返回字符串中的对象类,而不仅仅是原始响应字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59219308/