Java Amazon Lex AWS Lambda hook的Jackson JSON反序列化

Java Amazon Lex AWS Lambda hook的Jackson JSON反序列化,java,json,amazon-web-services,aws-lambda,aws-sdk,Java,Json,Amazon Web Services,Aws Lambda,Aws Sdk,我对AWS Lex Lambda hook中实现的反序列化有问题。我有一个AWS Lambda函数来验证用户输入,但我不断收到JSONMapping错误。 Lex json如下所示: { "currentIntent": { "name": "intent-name", "slots": { "slot-name": "value", "slot-name": "value", "slot-name": "value" },

我对AWS Lex Lambda hook中实现的反序列化有问题。我有一个AWS Lambda函数来验证用户输入,但我不断收到JSONMapping错误。 Lex json如下所示:

{
  "currentIntent": {
    "name": "intent-name",
    "slots": {
      "slot-name": "value",
      "slot-name": "value",
      "slot-name": "value"
    },
    "confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)",
  },
  "bot": {
    "name": "bot-name",
    "alias": "bot-alias",
    "version": "bot-version"
  },
  "userId": "User ID specified in the POST request to Amazon Lex.",
  "inputTranscript": "Text used to process the request",
  "invocationSource": "FulfillmentCodeHook or DialogCodeHook",
  "outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
  "messageVersion": "1.0",
  "sessionAttributes": { 
     "key1": "value1",
     "key2": "value2"
  }
}
我的反序列化JSON的Java bean是:

public class RequestInput {
    public class CurrentIntent {
        @JsonProperty("name")
        String name;
        @JsonProperty("slots")
        Map<String, String> slots;
        @JsonProperty("confirmationStatus")
        String confirmationStatus;

        public CurrentIntent(@JsonProperty("name") String name, @JsonProperty("slots") Map<String, String> slots, @JsonProperty("confirmationStatus") String confirmationStatus) {
            this.name = name;
            this.slots = slots;
            this.confirmationStatus = confirmationStatus;
        }
    }

    @JsonProperty("currentIntent")
    CurrentIntent currentIntent;
    @JsonProperty("bot")
    Map<String, String> bot;
    @JsonProperty("userId")
    String userId;
    @JsonProperty("inputTranscript")
    String inputTranscript;
    @JsonProperty("invocationSource")
    String invocationSource;
    @JsonProperty("outputDialogMode")
    String outputDialogMode;
    @JsonProperty("messageVersion")
    String messageVersion;
    @JsonProperty("sessionAttributes")
    Map<String, String> sessionAttributes;

    @JsonCreator
    public RequestInput(@JsonProperty("currentIntent") CurrentIntent currentIntent, @JsonProperty("bot") Map<String, String> bot,
                        @JsonProperty("userId") String userId, @JsonProperty("inputTranscript") String inputTranscript,
                        @JsonProperty("invocationSource") String invocationSource, @JsonProperty("outputDialogMode") String outputDialogMode,
                        @JsonProperty("messageVersion") String messageVersion, @JsonProperty("sessionAttributes") Map<String, String> sessionAttributes) {
        this.currentIntent = currentIntent;
        this.bot = bot;
        this.userId = userId;
        this.inputTranscript = inputTranscript;
        this.invocationSource = invocationSource;
        this.outputDialogMode = outputDialogMode;
        this.messageVersion = messageVersion;
        this.sessionAttributes = sessionAttributes;
    }

    @Override
    public String toString() {
        return "Intent " + currentIntent.toString() + "; Bot " + bot.toString() + "; InputTranscript " + inputTranscript;
    }
}

向类RequestInput添加默认构造函数。此错误通常表示无法实例化要与接收到的JSON映射的类:

 public RequestInput() {}

@Gili你们找到解决这个问题的办法了吗?同样的问题,当请求输入被反序列化时,
@JsonCreator
被完全忽略。@Françoisbaune我猜AWS使用的是不支持
@JsonCreator
的旧版本Jackson。我通过向lambda发送
字符串
输入,然后使用最新版本的Jackson实例化我自己的
ObjectMapper
,并自己反序列化对象来解决这个问题。这很好用。谢谢@Gili,这很有道理,我们会试试的!
 public RequestInput() {}