I am receiving JSON from SNS topic, which I believe is not correct
{
"Type":"Notification",
"MessageId":"message-id-is-this",
"TopicArn":"bouncer.topic.name.here",
"Message":"{\"notificationType\":\"Bounce\",\"bounce\":{\"bounceType\":\"Permanent\",\"bounceSubType\":\"General\",\"bouncedRecipients\":[{\"emailAddress\":\"bounce@simulator.amazonses.com\",\"action\":\"failed\",\"status\":\"5.1.1\",\"diagnosticCode\":\"smtp; 550 5.1.1 user unknown\"}],\"timestamp\":\"2017-04-24T12:58:05.716Z\",\"feedbackId\":\"feedback.id.is.here\",\"remoteMtaIp\":\"192.168.10.1\",\"reportingMTA\":\"dsn; smtp.link.here\"},\"mail\":{\"timestamp\":\"2017-04-24T12:58:05.000Z\",\"source\":\"senderEmail@domainname.com\",\"sourceArn\":\"arn:aws:ses:us-east-1:someid:identity/some@domain.org\",\"sourceIp\":\"127.0.0.1\",\"sendingAccountId\":\"sending.account.id.is.this\",\"messageId\":\"message-id-is-this\",\"destination\":[\"bounce@simulator.amazonses.com\"]}}",
"Timestamp":"2017-04-24T12:58:05.757Z",
"SignatureVersion":"1",
"Signature":"signature.link",
"SigningCertURL":"certificate.link.here",
"UnsubscribeURL":"un.subscribe.link"
}
The problem is with "Message" attribute which instead of holding an object, is referring to string of an object
contains
"Message":"{\"key\":\"value\"}"
instead of
"Message":{"key":"value"}"
hence not mapped to Message class
Temporarily I solved this problem by receiving into string variable and then convert it
private String Message;
private Message objMessage;
and then
Notification noti = toObject(jsonString, Notification.class);
Message msg = toObject(noti.getMessage(), Message.class);
noti.setObjMessage(msg);
for transformation, I am using ObjectMapper.readValue(...)
What is the correct way to solve this problem?