aws / aws/aws-lambda-java-libs

EventLoader unable to correctly deserialize posted json body data for APIGateway events

Aberta
#432 2 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Java
Estrelas
548
Forks
241
Merge médio
2d 5min
PRs com merge (30d)
11

Descrição

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?

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Comece lendo EventLoader e o tratamento do body de APIGatewayV2HTTPEvent; em seguida, reproduza a falha com broken.json do exemplo de JUnit. Compare os exemplos documentados de body em formato de string com o caso publicado de objeto JSON. Considera-se concluído quando o projeto tiver uma solução testada e claramente documentada para esse formato de entrada.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
aws, java
Domínio
api, testing-qa
Tipo de issue
Bug
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.