我目前正在从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(),但是我无法弄清楚如何使用该类生成String响应输出。
我可以在班级获得以下内容的字符串:
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
myFunction(){
return toJsonString(responseBuilder.build().get());
}
public String toJsonString(Response response)throws IOException {
return OBJECT_MAPPER.writeValueAsString(response);
}