diff --git a/Libraries/src/Amazon.Lambda.Serialization.Json/JsonSerializer.cs b/Libraries/src/Amazon.Lambda.Serialization.Json/JsonSerializer.cs index c673e9492..34c3afd19 100644 --- a/Libraries/src/Amazon.Lambda.Serialization.Json/JsonSerializer.cs +++ b/Libraries/src/Amazon.Lambda.Serialization.Json/JsonSerializer.cs @@ -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)) @@ -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>