Amazon.Lambda.Serialization.SystemTextJson.LambdaJsonSerializer uses different property casing than Amazon.Lambda.Serialization.Json.JsonSerializer
See original GitHub issueIt appears that the default casing behavior has changed between Amazon.Lambda.Serialization.Json.JsonSerializer
and Amazon.Lambda.Serialization.SystemTextJson.LambdaJsonSerializer
.
Here is some sample code to test the difference:
// create an instance to serialize
var record = new Record {
Foo = "Hello world!"
};
// show serialization with original Lambda serializer based on Newtonsoft.Json
var oldSerializer = SerializeWith(record, new Amazon.Lambda.Serialization.Json.JsonSerializer());
Console.WriteLine($"Amazon.Lambda.Serialization.Json.JsonSerializer: {oldSerializer}");
// show serialization with new Lambda serializer based on System.Text.Json
var newSerializer = SerializeWith(record, new Amazon.Lambda.Serialization.SystemTextJson.LambdaJsonSerializer());
Console.WriteLine($"Amazon.Lambda.Serialization.SystemTextJson.LambdaJsonSerializer: {newSerializer}");
// show serialization with System.Json.Text
var jsonTextSerializer = System.Text.Json.JsonSerializer.Serialize<Record>(record);
Console.WriteLine($"System.Text.Json.JsonSerializer: {jsonTextSerializer}");
// local functions
string SerializeWith<T>(T value, Amazon.Lambda.Core.ILambdaSerializer serializer) {
using var buffer = new MemoryStream();
serializer.Serialize<T>(value, buffer);;
return System.Text.Encoding.UTF8.GetString(buffer.ToArray());
}
The above code produces the following output:
Amazon.Lambda.Serialization.Json.JsonSerializer: {"Foo":"Hello world!"}
Amazon.Lambda.Serialization.SystemTextJson.LambdaJsonSerializer: {"foo":"Hello world!"}
System.Text.Json.JsonSerializer: {"Foo":"Hello world!"}
Issue Analytics
- State:
- Created 3 years ago
- Comments:44 (33 by maintainers)
Top Results From Across the Web
Improved AWS Lambda JSON Serialization in C# | Medium
Lambda.Serialization.Json nuget package to deserialize/serialize your lambda function inputs/outputs. This is based on the very popular JSON.NET library that ...
Read more >Does Amazon.Lambda.Serialization.Json.JsonSerializer ...
I have the [JsonIgnore] attribute on certain properties of the objects (classes) being passed in. If these properties are called in their state, ......
Read more >Lambda function handler in C# - AWS ...
SystemTextJson NuGet package. This library uses the native .NET Core JSON serializer to handle serialization. This package provides a performance improvement ...
Read more >A better serializer for Lambda - Tech Rants by Panos
This package contains a custom Amazon.Lambda.Core.ILambdaSerializer implementation which uses System.Text.Json to serialize/deserialize .NET ...
Read more >Amazon.Lambda.Serialization.SystemTextJson 2.3.1
This package contains a custom Amazon.Lambda.Core.ILambdaSerializer implementation which uses System.Text.Json to serialize/deserialize .NET types in Lambda ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Is it possible to keep this issue in topic?
Hi there I’m encountering this problem in Step Functions after switching the lambda Tasks over to .Net 3.1 + the new serializer. It’s wreaking havoc because the output now is in camelcase so the next state machine shape tries to evaluate the new JSON using the Amazon States Language and throws a Step Function exception.
There is a a kludgy workaround for the moment. By setting the
LAMBDA_NET_SERIALIZER_DEBUG=true
in the environment variable, the_.options
is never set in the serializer causing the case to be returned untouched. I’m not sure if that will result in other repercussions other than additional JSON being emitted into the Cloudwatch Logs. https://github.com/aws/aws-lambda-dotnet/blob/master/Libraries/src/Amazon.Lambda.Serialization.SystemTextJson/LambdaJsonSerializer.cs#L69-L90IMO, it would be a pain to decorate all of our models with the
[JsonPropertyName]
decoration as our models are buried in a number of nuget libraries. Ideally I’d like the default behavior to return to the original PascalCasing as before but I’m fine with using an explicitPascalCaseLambdaJsonSerializer
with the lambdas when it is called in our Step Function project.Thanks!