Amazon Lex AWS Lambda挂钩的Jackson JSON反序列化

编程入门 行业动态 更新时间:2024-10-10 19:25:32
本文介绍了Amazon Lex AWS Lambda挂钩的Jackson JSON反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在AWS Lex Lambda挂钩中实现的反序列化有问题.我有一个AWS Lambda函数来验证用户输入,但是我不断收到JSONMapping错误. Lex json是这样的:

I have a problem with deserialization implemented in AWS Lex Lambda hook. I have an AWS Lambda function to validate the user input, but I keep getting JSONMapping errors. The Lex json is like this:

{ "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是:

And my Java bean for deserializing this JSON is:

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.toString()方法,但我不断收到此错误:

In the handler class I just try to invoke RequestInput.toString() method, but I keep getting this error:

An error occurred during JSON parsing: java.lang.RuntimeException java.lang.RuntimeException: An error occurred during JSON parsing Caused by: java.io.UncheckedIOException: com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class comelit.lex.LexIntercomCallValidate$RequestInput]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?) at [Source: lambdainternal.util.NativeMemoryAsInputStream@55d56113; line: 1, column: 2] Caused by: com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class comelit.lex.LexIntercomCallValidate$RequestInput]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?) at [Source: lambdainternal.util.NativeMemoryAsInputStream@55d56113; line: 1, column: 2] at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148) at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1106) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:296) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:133) at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1511) at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1102)

推荐答案

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

Add a default constructor to class RequestInput. This error generally indicates the inability to instantiate the class to be mapped with the received JSON:

public RequestInput() {}

更多推荐

Amazon Lex AWS Lambda挂钩的Jackson JSON反序列化

本文发布于:2023-11-28 06:01:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641216.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列化   AWS   Lex   Amazon   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!