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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Libraries/src/Amazon.Lambda.Serialization.Json/JsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ public class JsonSerializer : ILambdaSerializer
private bool debug;

/// <summary>
/// Constructs instance of serializer.
/// Constructs instance of serializer. This constructor is usefull to
/// customize the serializer settings.
/// </summary>
public JsonSerializer()
/// <param name="customizeSerializerSettings">A callback to customize the serializer settings.</param>
public JsonSerializer(Action<JsonSerializerSettings> customizeSerializerSettings)
{
JsonSerializerSettings settings = new JsonSerializerSettings();
customizeSerializerSettings(settings);

// Set the contract resolver *after* the custom callback has been
// invoked. This makes sure that we always use the good resolver.
settings.ContractResolver = new AwsResolver();

serializer = Newtonsoft.Json.JsonSerializer.Create(settings);

if (string.Equals(Environment.GetEnvironmentVariable(DEBUG_ENVIRONMENT_VARIABLE_NAME), "true", StringComparison.OrdinalIgnoreCase))
Expand All @@ -36,6 +43,14 @@ public JsonSerializer()
}
}

/// <summary>
/// Constructs instance of serializer.
/// </summary>
public JsonSerializer()
:this(customizeSerializerSettings: _ => { /* Nothing to customize by default. */ })
{
}

/// <summary>
/// Constructs instance of serializer using custom converters.
/// </summary>
Expand Down