aws / aws/aws-lambda-java-libs
EventLoader unable to correctly deserialize posted json body data for APIGateway events
- 主要語言
- Java
- 星號
- 548
- 分支
- 241
- 平均合併
- 2 天 5 分鐘
- 30 天內合併 PR
- 11
描述
Using aws-lambda-java-tests v 1.1.1 and attempting to write a unit test for my lambda function handler (integrated with API Gateway).
Here is a snippet from my junit test - attempting to load a test event to pass to the handler function:
```
APIGatewayV2HTTPEvent event = EventLoader.loadApiGatewayHttpEvent("events/broken.json");
//proceed to pass the event to the function handler
```
The contents of the file 'broken.json' are as follows :
```
{
"version": "2.0",
"headers": {
"content-type":"application/json"
},
"requestContext": {
"accountId": "123456789012",
"apiId": "api-id"
}
,
"body": {
"firstName":"John",
"lastName":"Doe",
"nickName":"Jonny D"
},
"isBase64Encoded": false
}
```
All the documentation and examples I've found only use a string as the body, but this is a fairly common use case (an HTTP API accepting json data into a POST for updating information). From above, the body has a simple json object structure representing a person. Because the APIGatewayV2HTTPEvent defines the body as a string, the EventLoader fails with the following exception:
```
java.io.UncheckedIOException: com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
at [Source: (BufferedInputStream); line: 11, column: 11] (through reference chain: com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent["body"])
```
What am I missing here? Is this a deficiency in the EventLoader class, or am I attempting to test this behavior in the wrong way?
貢獻指南
研究方向
先閱讀 EventLoader 以及 APIGatewayV2HTTPEvent 的 body 處理邏輯,然後使用 JUnit 範例中的 broken.json 重現失敗。將文件中記錄的字串 body 範例與已提交的 JSON-object 情況進行比較。完成的標準是,專案針對這種輸入形式有經過測試且文件清楚的解決方案。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- aws, java
- 領域
- api, testing-qa
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100