aws / aws/aws-lambda-dotnet

JsonSerializer.Deserialize<T> returns invalid object when called by TypeConverter within AWS Lambda Test Tool

Open
#1,453 3 comments 0 reactions 0 assignees View on GitHub
bug module/lambda-test-tool p2 queued
Dominant language
C#
Stars
1.7k
Forks
503
Avg merge
1d 5h
Merged PRs (30d)
18

Description

### Describe the bug

When I'm running some code in the test tool, I come across an issue, when System.Text.Json.JsonSerializer.Deserialize returns different results depending on whether it's being called from the top level or from a System.ComponentModel.TypeConverter method.

This is best illustrated with code (see attachment)

[lambda-test-tool.zip](https://github.com/aws/aws-lambda-dotnet/files/10959736/lambda-test-tool.zip)

Run:

```
dotnet tool restore
dotnet build
dotnet dotnet-lambda-test-tool-6.0 --no-ui --function-handler Lambda::Main.Lambda::Handler --pause-exit false
```

Output:

```
AWS .NET Core 6.0 Mock Lambda Test Tool (0.12.7)
Loaded local Lambda runtime from project output /home/alex.bolenok/Projects/lambda-test-tool/bin/Debug/net6.0
Executing Lambda function without web interface
... Using function handler Lambda::Main.Lambda::Handler
... No payload configured. If a payload is required set the --payload switch to a file path or a JSON document.
... Setting AWS_PROFILE environment variable to default.
... No default AWS region configured. The --region switch can be used to configure an AWS Region.
Captured Log information:
test
True
Main.S3Bucket
Main.S3Bucket
>>>> False <<<<

Request executed successfully
Response:
```

This issue seems to be specific to the test tool (when I run this code in an actual Lambda, or in a console app, it works as expected).

### Expected Behavior

`TypeDescriptor.GetConverter(typeof T).ConvertFrom` and `JsonSerializer.Deserialize` both return objects of the same type `T`.

### Current Behavior

`TypeDescriptor.GetConverter(typeof T).ConvertFrom` and `JsonSerializer.Deserialize` return objects of different types.

### Reproduction Steps

Run:

```
dotnet tool restore
dotnet build
dotnet dotnet-lambda-test-tool-6.0 --no-ui --function-handler Lambda::Main.Lambda::Handler --pause-exit false
```

Output:

```
AWS .NET Core 6.0 Mock Lambda Test Tool (0.12.7)
Loaded local Lambda runtime from project output /home/alex.bolenok/Projects/lambda-test-tool/bin/Debug/net6.0
Executing Lambda function without web interface
... Using function handler Lambda::Main.Lambda::Handler
... No payload configured. If a payload is required set the --payload switch to a file path or a JSON document.
... Setting AWS_PROFILE environment variable to default.
... No default AWS region configured. The --region switch can be used to configure an AWS Region.
Captured Log information:
test
True
Main.S3Bucket
Main.S3Bucket
>>>> False <<<<

Request executed successfully
Response:
```

### Possible Solution

There is something weird in the way the test tool calles the framework methods. The actual lambda runtime works fine.

### Additional Information/Context

_No response_

### AWS .NET SDK and/or Package version used

```
{
"version": 1,
"isRoot": true,
"tools": {
"amazon.lambda.testtool-6.0": {
"version": "0.12.7",
"commands": [
"dotnet-lambda-test-tool-6.0"
]
}
}
}
```

```



```

### Targeted .NET Platform

.NET 6

### Operating System and version

Amazon Linux

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.