Is it possible to use the EnumMemberAttribute
when deserializing JSON in a .Net AWS Lambda?
I'm trying to deserialize the following payload into the following object.
Payload:
{
"Option" : "Option 01"
}
Object definition:
public enum Option
{
[EnumMember(Value = "Option 01")]
One,
[EnumMember(Value = "Option 02")]
Two
}
public class Payload
{
[JsonConverter(typeof(JsonStringEnumConverter))]
public Option Option { get; set; }
}
But this throws an exception suggesting that the DefaultLambdaJsonSerializer
doesnt support the EnumMemberAttribute
:
Amazon.Lambda.Serialization.SystemTextJson.JsonSerializerException: Error converting the Lambda event JSON payload to type MyProject.Payload: The JSON value could not be converted to MyProject.Option. Path: $.Option | LineNumber: 1 | BytePositionInLine: 26. at Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer.Deserialize[T](Stream requestStream)
With the current object definition above, the the values One
and Two
can be deserialized (along with any int
value).
For some more context, the Payload
object is an input parameter to my lambda, so my function handler is as follows, and I'm just pasting the JSON payload into the mock lambda test tool while debugging the lambda in Visual Studio.
public void FunctionHandler(Payload payload, ILambdaContext context)
{
// ...
}