Amazon.Lambda.Serialization.SystemTextJson
2.4.4
Prefix Reserved
dotnet add package Amazon.Lambda.Serialization.SystemTextJson --version 2.4.4
NuGet\Install-Package Amazon.Lambda.Serialization.SystemTextJson -Version 2.4.4
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />
<PackageVersion Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" />
paket add Amazon.Lambda.Serialization.SystemTextJson --version 2.4.4
#r "nuget: Amazon.Lambda.Serialization.SystemTextJson, 2.4.4"
#addin nuget:?package=Amazon.Lambda.Serialization.SystemTextJson&version=2.4.4
#tool nuget:?package=Amazon.Lambda.Serialization.SystemTextJson&version=2.4.4
Amazon.Lambda.Serialization.SystemTextJson
This package contains a custom Amazon.Lambda.Core.ILambdaSerializer
implementation which uses System.Text.Json to
serialize/deserialize .NET types in Lambda functions. This serializer targets .NET Core 3.1 so can not be used with
the .NET Core 2.1 Lambda runtime.
If targeting .NET Core 3.1 this serializer is highly recommend over Amazon.Lambda.Serialization.Json and can significantly reduce cold start performance in Lambda.
This serializer can be present on the assembly or on the handler method. If you specify both, the method attribute takes priority.
Here is an example of setting this attribute on the assembly.
[assembly: Amazon.Lambda.Core.LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
And this is how the method can be applied to the handler method.
[Amazon.Lambda.Core.LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
public Response CustomSerializerMethod(Request input)
{
...
}
Using C# source generator for serialization
C# 9 provides source generators, which allow code generation during compilation. This can reduce the use of reflection APIs and improve application startup time. .NET 6 updated the native JSON library System.Text.Json to use source generators, allowing JSON parsing without requiring reflection APIs.
To use the source generator for JSON serializing in Lambda, you must define a new empty class
in your project that derives from System.Text.Json.Serialization.JsonSerializerContext
. This
class must be a partial class because the source generator adds code to this class to handle
serialization. On the empty partial class, add the JsonSerializable
attribute for each .NET
type the source generator must generate the serialization code for.
Here is an example called HttpApiJsonSerializerContext that registers the Amazon API Gateway HTTP API event and response types to have the serialization code generated:
[JsonSerializable(typeof(APIGatewayHttpApiV2ProxyRequest))]
[JsonSerializable(typeof(APIGatewayHttpApiV2ProxyResponse))]
public partial class HttpApiJsonSerializerContext : JsonSerializerContext
{
}
To register the source generator for serialization use the LambdaSerializer
attribute
passing in the SourceGeneratorLambdaJsonSerializer
type along with the custom context
type (i.e. HttpApiJsonSerializerContext
) as the generic parameter.
[assembly: LambdaSerializer(
typeof(SourceGeneratorLambdaJsonSerializer
<APIGatewayExampleImage.HttpApiJsonSerializerContext>))]
Customizing serialization options
Both DefaultLambdaJsonSerializer
and SourceGeneratorLambdaJsonSerializer
construct an
instance of JsonSerializerOptions
that is used to customize the serialization and deserialization
of the Lambda JSON events. For example adding special converters and naming policies.
To further customize the JsonSerializerOptions
create a new type extending from extend
either DefaultLambdaJsonSerializer
or SourceGeneratorLambdaJsonSerializer
and pass
in an Action
customizer to the base constructor. Then register the new type as the
serializer using the LambdaSerializer
attribute. Below is an example of a custom serializer.
public class CustomLambdaSerializer : DefaultLambdaJsonSerializer
{
public CustomLambdaSerializer()
: base(CreateCustomizer())
{ }
private static Action<JsonSerializerOptions> CreateCustomizer()
{
return (JsonSerializerOptions options) =>
{
// Customize options
};
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Amazon.Lambda.Core (>= 2.3.0)
-
net6.0
- Amazon.Lambda.Core (>= 2.3.0)
-
net8.0
- Amazon.Lambda.Core (>= 2.3.0)
NuGet packages (32)
Showing the top 5 NuGet packages that depend on Amazon.Lambda.Serialization.SystemTextJson:
Package | Downloads |
---|---|
Amazon.Lambda.AspNetCoreServer
Amazon.Lambda.AspNetCoreServer makes it easy to run ASP.NET Core Web API applications as AWS Lambda functions. |
|
AWS.Lambda.Powertools.Logging
Powertools for AWS Lambda (.NET) - Logging package. |
|
AWS.Lambda.Powertools.Tracing
Powertools for AWS Lambda (.NET) - Tracing package. |
|
Kralizek.Lambda.Template
A structured template to create AWS Lambda in C#. It supports Logging, Dependency Injection and Configuration like ASP.NET Core projects do. |
|
LambdaSharp
Serverless .NET for AWS - Lambda Library |
GitHub repositories (18)
Showing the top 18 popular GitHub repositories that depend on Amazon.Lambda.Serialization.SystemTextJson:
Repository | Stars |
---|---|
mongodb/mongo-csharp-driver
The Official C# .NET Driver for MongoDB
|
|
aws/aws-sdk-net
The official AWS SDK for .NET. For more information on the AWS SDK for .NET, see our web site:
|
|
aws/aws-lambda-dotnet
Libraries, samples and tools to help .NET Core developers develop AWS Lambda functions.
|
|
TelegramBots/Telegram.Bot.Examples
Examples for the Telegram.Bot C# Library
|
|
exceptionless/Exceptionless.Net
Exceptionless clients for the .NET platform
|
|
DataDog/dd-trace-dotnet
.NET Client Library for Datadog APM
|
|
aws/aws-extensions-for-dotnet-cli
Extensions to the dotnet CLI to simplify the process of building and publishing .NET Core applications to AWS services
|
|
axzxs2001/Asp.NetCoreExperiment
原来所有项目都移动到**OleVersion**目录下进行保留。新的案例装以.net 5.0为主,一部分对以前案例进行升级,一部分将以前的工作经验总结出来,以供大家参考!
|
|
aws-samples/serverless-test-samples
This repository is designed to provide guidance for implementing comprehensive test suites for serverless applications.
|
|
Elfocrash/aws-videos
|
|
jorgevgut/airquality-mx
|
|
aws-powertools/powertools-lambda-dotnet
Powertools is a developer toolkit to implement Serverless best practices and increase developer velocity.
|
|
aws-samples/serverless-dotnet-demo
|
|
awslabs/dotnet-nativeaot-labs
A place to learn about and experiment with .NET NativeAOT on AWS.
|
|
hlaueriksson/CommandQuery
Command Query Separation for 🌐ASP.NET Core ⚡AWS Lambda ⚡Azure Functions ⚡Google Cloud Functions
|
|
Particular/docs.particular.net
All content for ParticularDocs
|
|
newrelic/newrelic-dotnet-agent
The New Relic .NET language agent.
|
|
LambdaSharp/LambdaSharpTool
Serverless .NET on AWS - λ# is a CLI and Framework for Rapid Application Development using .NET on AWS
|
Version | Downloads | Last updated |
---|---|---|
2.4.4 | 3,015,560 | 10/23/2024 |
2.4.3 | 4,326,675 | 4/25/2024 |
2.4.2 | 577,167 | 4/5/2024 |
2.4.1 | 4,073,355 | 2/16/2024 |
2.4.0 | 3,699,222 | 10/26/2023 |
2.3.1 | 9,370,276 | 2/2/2023 |
2.3.0 | 13,071,403 | 3/23/2022 |
2.2.0 | 6,312,045 | 11/5/2021 |
2.1.0 | 8,977,375 | 10/21/2020 |
2.0.2 | 606,443 | 9/16/2020 |
2.0.1 | 2,517,390 | 5/4/2020 |
2.0.0 | 1,444,290 | 4/28/2020 |
1.0.0 | 730,541 | 3/31/2020 |