我有来自dynamodb流的以下事件:
{
"Records": [
{
"eventID": "whatever",
"eventName": "INSERT",
"eventVersion": "1.1",
"eventSource": "aws:dynamodb",
"awsRegion": "eu-west-1",
"dynamodb": {
"ApproximateCreationDateTime": 12345678,
"Keys": {
"id": {
"S": "some-id"
},
"parentId": {
"S": "some-parent-id"
}
},
"SequenceNumber": "something",
"SizeBytes": 820,
"StreamViewType": "KEYS_ONLY"
},
"eventSourceARN": "some-arn"
}
]
}
这以InputStream
的形式出现在我的lambda函数中,因此我将其转换为JSON并尝试将其映射到StreamRecord
。
public static StreamRecord getStreamEventAsStreamRecord(final JsonNode input)
throws JsonProcessingException {
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
final StreamRecord record =
objectMapper.treeToValue(input, StreamRecord.serializableBuilderClass()).build();
return record;
}
我用它:
JsonNode event = objectMapper.readTree(input); // The input as outlines above coming from DDB streams
// assume that the Records array has been iterated
for(JsonNode record: records){
StreamRecord myrecord = getStreamEventAsStreamRecord(record);
}
调用myrecord.keys().keySet()
时,即使收到的有效负载中有密钥,我也会得到[]
。我对StreamRecord
的映射/序列化处理不正确吗?