GSON序列化SNSEvent导致小写字段(lambda期望将其大写)

我有一个lambda函数,该函数以snSEvent(http://javadox.com/com.amazonaws/aws-lambda-java-events/1.1.0/com/amazonaws/services/lambda/runtime/events/SNSEvent.html)作为输入,然后对其进行处理。为了编写一些集成测试用例,我想使用通过消息为字符串的lambda.invoke序列化snSEvent来调用此lambda

因此,为此,我正在执行GSON.toJson([snSEvent类型的对象]),并由此得到一个字符串。但是问题是,当我使用此字符串调用lambda时,我得到一个例外,该字符串的反序列化失败。

例如。 GSON.toJson正在反序列化为:

{
  "records": [
    {
      "eventsource": "aws:sns","eventVersion": "1.0","eventSubscriptionArn": "arn:aws:sns:us-west-2:{{{accountId}}}:ExampleTopic","sns": {
        "type": "Notification","messageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e","topicArn": "arn:aws:sns:us-west-2:{{accountId}}:ExampleTopic","subject": "example subject","message": "example message","timestamp": "1970-01-01T00:00:00.000Z","signatureversion": "1","signature": "EXAMPLE","signingCertUrl": "EXAMPLE","unsubscribeUrl": "EXAMPLE","messageAttributes": {
          "test": {
            "type": "String","value": "TestString"
          },"testBinary": {
            "type": "Binary","value": "TestBinary"
          }
        }
      }
    }
  ]
}

而实际上,它想要的是(用大写字母表示):

{
  "Records": [
    {
      "Eventsource": "aws:sns","EventVersion": "1.0","EventSubscriptionArn": "arn:aws:sns:us-west-2:{{{accountId}}}:ExampleTopic","sns": {
        "Type": "Notification","MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e","TopicArn": "arn:aws:sns:us-west-2:{{accountId}}:ExampleTopic","Subject": "example subject","Message": "example message","Timestamp": "1970-01-01T00:00:00.000Z","Signatureversion": "1","Signature": "EXAMPLE","SigningCertUrl": "EXAMPLE","UnsubscribeUrl": "EXAMPLE","MessageAttributes": {
          "Test": {
            "Type": "String","Value": "TestString"
          },"TestBinary": {
            "Type": "Binary","Value": "TestBinary"
          }
        }
      }
    }
  ]
}

有人知道为什么会这样吗?我该如何解决?调用lambda时是否应该使用其他对象代替snSEvent。

vorlor 回答:GSON序列化SNSEvent导致小写字段(lambda期望将其大写)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3133424.html

大家都在问