Skip to content

Commit f188153

Browse files
committed
fix: Correctly handle null values while deserializing JSON to MemoryStream in Amazon.Lambda.Serialization.Json
1 parent 50267e0 commit f188153

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Libraries/src/Amazon.Lambda.Serialization.Json/JsonToMemoryStreamDataConverter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public override bool CanConvert(Type objectType)
2424
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, NewtonsoftJsonSerializer serializer)
2525
{
2626
var dataBase64 = reader.Value as string;
27+
if (dataBase64 is null)
28+
return null;
29+
2730
return Common.Base64ToMemoryStream(dataBase64);
2831
}
2932

Libraries/test/EventsTests.Shared/EventTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,7 @@ public void SQSTest(Type serializerType)
13021302
Assert.Equal("b2", attribute2.StringListValues[1]);
13031303

13041304
Assert.Equal("String", attribute2.DataType);
1305+
Assert.Null(attribute2.BinaryValue);
13051306
}
13061307

13071308
Handle(sqsEvent);

Libraries/test/EventsTests.Shared/sqs-event.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
"Attribute2": {
2727
"stringValue": "AttributeValue2",
2828
"stringListValues": [ "b1", "b2" ],
29-
"binaryListValues": [ ],
30-
"dataType": "String"
29+
"binaryListValues": [],
30+
"dataType": "String",
31+
"binaryValue": null
3132
}
3233
}
3334
}

0 commit comments

Comments
 (0)