0

I'm presently migrating from the Java ASK-SDK v1 to Java ASK SDK v2.

I'm trying to return a webhook call using the ResponseBuilder class that I built my response up and the data is correct, however when I try to populate the HTTP body with the JSON text, the ResponseBuilder.toString() value doesn't just populate the data with just the string, I get the following:

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
}]

Is there another way to get the string for the body of the response? The BaseSkillResponse has a getResponse() call, however, I cannot figure out how to use the class to generate the String response output.

Ihor Patsian
  • 1,288
  • 2
  • 15
  • 25
Rich Elswick
  • 561
  • 5
  • 20

2 Answers2

0

I was able to get the string with the following in my 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);
 }
Rich Elswick
  • 561
  • 5
  • 20
  • unfortunately, the AttributeManager data is not present for session attributes, so this solution only works for single responses. – Rich Elswick Dec 09 '19 at 22:35
0

Solve this by doing the following:

        public String toJsonString(Response response)throws IOException 
        {
          JacksonSerializer jacksonSerializer = new JacksonSerializer();
          constructedResponse = jacksonSerializer.serialize(response);

          JSONObject jsonObject = new JSONObject();

          jsonObject.put("response",constructedResponse);
        }
Rich Elswick
  • 561
  • 5
  • 20