我正在尝试反序列化更新S3上的文件时向HTTPS端点发布的SNS消息。由于我找不到这样的SNS消息的任何标准包装类,我自己编写了包装器:
public class SnsNotificationMessage {
private final String type;
private final String messageId;
private final String topicArn;
private final String subject;
private final S3EventNotification message;
private final DateTime timestamp;
private final String signatureVersion;
private final String signature;
private final String signingCertURL;
private final String unsubscribeURL;
@JsonCreator
public SnsNotificationMessage(@JsonProperty("Type") String type,
@JsonProperty("MessageId")String messageId,
@JsonProperty("TopicArn") String topicArn,
@JsonProperty("Subject") String subject,
@JsonProperty("Message") S3EventNotification message,
@JsonProperty("Timestamp") DateTime timestamp,
@JsonProperty("SignatureVersion") String signatureVersion,
@JsonProperty("Signature") String signature,
@JsonProperty("SigningCertURL") String signingCertURL,
@JsonProperty("UnsubscribeURL") String unsubscribeURL) {
this.type = type;
this.messageId = messageId;
this.topicArn = topicArn;
this.subject = subject;
this.message = message;
this.timestamp = timestamp;
this.signatureVersion = signatureVersion;
this.signature = signature;
this.signingCertURL = signingCertURL;
this.unsubscribeURL = unsubscribeURL;
}
public String getType() {
return type;
}
public String getMessageId() {
return messageId;
}
public String getTopicArn() {
return topicArn;
}
public String getSubject() {
return subject;
}
public S3EventNotification getMessage() {
return message;
}
public DateTime getTimestamp() {
return timestamp;
}
public String getSignatureVersion() {
return signatureVersion;
}
public String getSignature() {
return signature;
}
public String getSigningCertURL() {
return signingCertURL;
}
public String getUnsubscribeURL() {
return unsubscribeURL;
}
}
无论如何,当我尝试反序列化它时,它似乎无法反序列化S3EventNotification对象:
Exception in thread "main" com.amazonaws.AmazonClientException: Unable to parse Json String.
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class com.amazonaws.services.s3.event.S3EventNotification] from String value ('{"Records":[{"eventVersion":"2.0","eventSource":"aws:s3","awsRegion":"eu-central-1","eventTime":"2016-06-24T16:38:46.692Z","eventName":"ObjectCreated:Put","userIdentity":{"principalId":"AWS:AIDAJYIVJE6VBFWIRPGI4"},"requestParameters":{"sourceIPAddress":"54.239.6.12"},"responseElements":{"x-amz-request-id":"4AF210318149235D","x-amz-id-2":"fyHT/8YQYwLehZhMK41NZVCVI9z5UiL9F3o2iBzI9Qea7P5v6GY/9qlaUZLaTnbFX6CLf7ts6Ss="},"s3":{"s3SchemaVersion":"1.0","configurationId":"ManualsUpdate","bucket":{"name":"mybucketname","ownerIdentity":{"principalId":"A3PMDPD5DZRTH7"},"arn":"arn:aws:s3:::mybucket"},"object":{"key":"manuals/velum/APP_B.pdf","size":819609,"eTag":"ebde6fb2ef4a041b40f0c88a36283ed9","sequencer":"00576D6206898586C7"}}}]}'); no single-String constructor/factory method
at [Source: {
"Type" : "Notification",
"MessageId" : "a377f3c7-e519-509a-9d23-bc20814f82d9",
"TopicArn" : "arn:aws:sns:eu-central-1:133857750848:Manual_Updates",
"Subject" : "Amazon S3 Notification",
"Message" : "{\"Records\":[{\"eventVersion\":\"2.0\",\"eventSource\":\"aws:s3\",\"awsRegion\":\"eu-central-1\",\"eventTime\":\"2016-06-24T16:38:46.692Z\",\"eventName\":\"ObjectCreated:Put\",\"userIdentity\":{\"principalId\":\"AWS:AIDAJYIVJE6VBFWIRPGI4\"},\"requestParameters\":{\"sourceIPAddress\":\"54.239.6.12\"},\"responseElements\":{\"x-amz-request-id\":\"4AF210318149235D\",\"x-amz-id-2\":\"fyHT/8YQYwLehZhMK41NZVCVI9z5UiL9F3o2iBzI9Qea7P5v6GY/9qlaUZLaTnbFX6CLf7ts6Ss=\"},\"s3\":{\"s3SchemaVersion\":\"1.0\",\"configurationId\":\"ManualsUpdate\",\"bucket\":{\"name\":\"mybucket\",\"ownerIdentity\":{\"principalId\":\"A3PMDPD5DZRTH7\"},\"arn\":\"arn:aws:s3:::mybucket\"},\"object\":{\"key\":\"manuals/velum/APP_B.pdf\",\"size\":819609,\"eTag\":\"ebde6fb2ef4a041b40f0c88a36283ed9\",\"sequencer\":\"00576D6206898586C7\"}}}]}",
"Timestamp" : "2016-06-24T16:38:46.802Z",
"SignatureVersion" : "1",
"Signature" : "WvEi+Y6DxDbXzqIjmbpJo1YHGDU+mgkRaMLlr6WQZkm53qpp8ch8cvWMtYq3LCYWiuQb6+95Gp+OfUFPulKCrxgis9KrHHJ8ozU8ZXI6Y8P693kNLYqEkro9DEjbaR63xw1Se+6KGpQm/kYJEn/AJCTr47sK3bmfsy4esuVWrw7F9PCUfJGzVfgB8S7z5N5DyPBROPAJ+1DyjPyYlv9AGM8Dw5LsdP4PjfOoEoKZZQ4iBJaKr5lFc7iDq+8SKGt0YwJWGAKYm08Lkx4oMBTojXBshK7cG6CUZbFCOXXG+F5cSffBENN1dK/1xrCvKDRdqc1+J4Y+JEDy/KCoPAcvEQ==",
"SigningCertURL" : "https://sns.eu-central-1.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem",
"UnsubscribeURL" : "https://sns.eu-central-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-central-1:133857750848:Manual_Updates:9c1bb86d-836c-46d4-bd44-f7625f77f7bf"
}; line: 5, column: 39] (through reference chain: org.project.resources.notifications.models.SnsNotificationMessage["Message"])
奇怪的是,如果我尝试仅单独反序列化S3EventNotification字符串,它会正确地反序列化,所以看起来它是将S3EventNotification作为参数传递给构造函数的东西。我该怎么办?
答案 0 :(得分:0)
好的,我找到了答案。问题是Message值是" global"中的一个String。字符串,而不是对象。