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

add constructor that allows changing the serializer settings #503

Merged
merged 1 commit into from
Aug 15, 2019

Conversation

mabead
Copy link
Contributor

@mabead mabead commented Aug 12, 2019

Issue #500

Description of changes:

As described in related issue, I add a constructor that makes it easy to customize the lambda json serialization settings.

Here's an example of how the json serialization settings can be changed by using a derived class:

public class MySerializer : JsonSerializer
{
    public MySerializer()
        : base(CustomizeSerializerSettings)
    {
    }

    private static void CustomizeSerializerSettings(JsonSerializerSettings serializerSettings)
    {
        serializerSettings.Converters = new List<JsonConverter>
        {
            new StringEnumConverter() { CamelCaseText = false }
        };
    }
}

The new serializer could then be used like this:

[assembly: LambdaSerializer(typeof(MySerializer))]

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

@normj normj merged commit 2c79514 into aws:master Aug 15, 2019
@normj
Copy link
Member

normj commented Aug 16, 2019

Version 1.6.0 of Amazon.Lambda.Serialization.Json is out with the PR. Thanks for the PR!

@mabead mabead deleted the custom-serializer-settings branch August 21, 2019 14:13
@UrmaGurd
Copy link

Is there an example of how to use this to deserialize strings to enums with Lambda functions?

My lambda function is currently using

[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

How do I change this to support enums / string conversions?

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.

3 participants