alexa / alexa-skills-kit-sdk-for-java

The Alexa Skills Kit SDK for Java helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
http://developer.amazon.com/ask
Apache License 2.0
816 stars 746 forks source link

@JsonInclude(Include.NON_DEFAULT) on getShouldEndSession() breaks sessions #10

Closed kenpaulsen closed 6 years ago

kenpaulsen commented 8 years ago

The "default" for a boolean is false, regardless of the "initial" value set by the class. The effect of adding the @JsonInclude(Include.NON_DEFAULT) annotation means that anytime the setShouldEndSession(...) method is called with false, this property will be omitted from the JSON output. When deserialized, it will pickup the "initial" value of true... meaning with this annotation set, this property is effectively true after deserialization regardless of its original value.

One fix is to simply remove this annotation.

The error is on this line: https://github.com/amzn/alexa-skills-kit-java/blob/master/src/com/amazon/speech/speechlet/SpeechletResponse.java#L57

KayLerch commented 8 years ago

Meanwhile you can wrap SpeechletResponse in your own class and override getShouldEndSession.

@Override @JsonInclude public boolean getShouldEndSession() { return super.getShouldEndSession(); }

See an example of a wrapper, which is also way better to build SpeechletResponse like

final SpeechletResponse response = AlexaSpeechletResponse .ask() .withSsml("Some <p>SSML</p>") .withRepromptText("Some reprompt text.") .withSimpleCardContent("Some card content.") .withSimpleCardTitle("A card's title") .build();

Have fun: https://gist.github.com/KayLerch/8bfcb2d3b895e0bfccaf34d8f8550e9e

kenpaulsen commented 8 years ago

Thanks Kay! Yes, I overrode SpeechletResponse and did something very similar in my code to work around this.

Also your fluent builder looks great!

bgreen1005 commented 8 years ago

We faced this issue when using the alexa-skills-kit 1.1.3 with the aws-java-sdk-core 1.11.0 jar. The aws-java-sdk-core pulls in jackson-databind 2.5.3 which cannot handle the above annotation, whereas alexa-skills-kit 1.1.3 pulls in jackson-databind 2.3.2, which can handle the Include.NON_DEFAULT annotation value.

In our gradle build script, we simply excluded the jackson-databind transitive dependency from the aws jars, and have had no issues since then.

ghost commented 6 years ago

Closing due to inactivity but please feel free to reopen if this issue persists!