forked from aws/aws-lambda-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAwsResolver.cs
73 lines (71 loc) · 3.25 KB
/
AwsResolver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
namespace Amazon.Lambda.Serialization.Json
{
/// <summary>
/// Custom contract resolver for handling special event cases.
/// </summary>
internal class AwsResolver : DefaultContractResolver
{
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization);
// S3 events use non-standard key formatting for request IDs and need to be mapped to the correct properties
if (type.FullName.Equals("Amazon.S3.Util.S3EventNotification+ResponseElementsEntity", StringComparison.Ordinal))
{
foreach (JsonProperty property in properties)
{
if (property.PropertyName.Equals("XAmzRequestId", StringComparison.Ordinal))
{
property.PropertyName = "x-amz-request-id";
}
else if (property.PropertyName.Equals("XAmzId2", StringComparison.Ordinal))
{
property.PropertyName = "x-amz-id-2";
}
}
}
else if (type.FullName.Equals("Amazon.Lambda.KinesisEvents.KinesisEvent+Record", StringComparison.Ordinal))
{
foreach (JsonProperty property in properties)
{
if (property.PropertyName.Equals("Data", StringComparison.Ordinal))
{
property.MemberConverter = new JsonToMemoryStreamDataConverter();
}
else if (property.PropertyName.Equals("ApproximateArrivalTimestamp", StringComparison.Ordinal))
{
property.MemberConverter = new JsonNumberToDateTimeDataConverter();
}
}
}
else if (type.FullName.Equals("Amazon.DynamoDBv2.Model.StreamRecord", StringComparison.Ordinal))
{
foreach (JsonProperty property in properties)
{
if (property.PropertyName.Equals("ApproximateCreationDateTime", StringComparison.Ordinal))
{
property.MemberConverter = new JsonNumberToDateTimeDataConverter();
}
}
}
else if (type.FullName.Equals("Amazon.DynamoDBv2.Model.AttributeValue", StringComparison.Ordinal))
{
foreach (JsonProperty property in properties)
{
if (property.PropertyName.Equals("B", StringComparison.Ordinal))
{
property.MemberConverter = new JsonToMemoryStreamDataConverter();
}
else if (property.PropertyName.Equals("BS", StringComparison.Ordinal))
{
property.MemberConverter = new JsonToMemoryStreamListDataConverter();
}
}
}
return properties;
}
}
}