Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NETCore31] Add support for using System.Text.Json as the serialization parser #568

Merged
merged 13 commits into from
Mar 4, 2020

Conversation

normj
Copy link
Member

@normj normj commented Jan 18, 2020

Issue #, if available:
#544

Description of changes:
.NET Core 3.0 added a new JSON serialization called System.Text.Json. This PR creates new Lambda serialization called Amazon.Lambda.Serialization.SystemTextJson that will be based on System.Text.Json. Unlike Newtonsoft's JSON parser System.Text.Json is built into the framework and is optimized for speed.

This will released as part of the upcoming Lambda .NET Core 3.1 and will only target .NET Core 3.1. There will not be a .NET Standard 2.0 which would make it available to .NET Core 2.1 Lambda functions because the event packages like Amazon.Lambda.S3 would have to take a dependency on the System.Text.Json Nuget package.

In my anecdotal testing I have seen some good cold start performance improvements using this library. For those that are currently trying .NET Core 3.1 on Lambda using the custom runtime feature here are preview versions of the impacted NuGet packages to try out.

https://normj-packages.s3.us-west-2.amazonaws.com/System.Text.Json-2020-01-17.zip

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@msimpsonnz
Copy link

There is a .NET Standard package for this which makes it available to 2.1
Would be nice if the SDK’s could align
https://www.nuget.org/packages/System.Text.Json

_options = new JsonSerializerOptions()
{
IgnoreNullValues = true,
PropertyNameCaseInsensitive = true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there more annotations that could be added that would make it possible to remove this? It comes with a performance penalty to some degree, so would be better if it could be left off.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking users could use the constructor that takes in Action<JsonSerializerOptions> customizer to customize or remove these settings. I'm open to suggestions to make it easier.

@normj
Copy link
Member Author

normj commented Jan 21, 2020

@msimpsonnz That was my original attention to use the NuGet package for .NET Core 2.1. The problem is the AWS event packages require customization of the .NET Property name to JSON Property name mapping. For Newtonsoft we could add System.Runtime.Serialization.DataMember attributes to the event packages like Amazon.Lambda.CloudWatchLogsEvents to handle the customization. For System.Text.Json it doesn't recognize System.Runtime.Serialization.DataMember attributes and instead you have to use System.Text.Json.Serialization.JsonPropertyName. That means in order to support System.Text.Json for .NET Core 2.1 Lambda functions the event packages would have to take a NuGet package dependency on a System.Text.Json. I don't want to force anybody using .NET Core 2.1 to have to include any other NuGet package especially if they are not using it because they are using the Newtonsoft serializer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants