2016-06-24 2 views
0

S3上のファイルが更新されたときにHTTPSエンドポイントに送信されるSNSメッセージを逆シリアル化しようとしています。私は、このようなSNSのメッセージのための任意の標準ラッパークラスを見つけることができませんでしたので、私はラッパーを自分で書いた:JsonMappingException:S3ファイル更新からのジャーナルによる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

私の答えが見つかりました。問題は、メッセージ値がオブジェクトではなく「グローバル」String内のStringであることでした。

関連する問題