Je reçois JSON sujet SNS, qui je crois est pas correctComment analyser correctement SES rebondissait notification JSON SNS en Java
{
"Type":"Notification",
"MessageId":"message-id-is-this",
"TopicArn":"bouncer.topic.name.here",
"Message":"{\"notificationType\":\"Bounce\",\"bounce\":{\"bounceType\":\"Permanent\",\"bounceSubType\":\"General\",\"bouncedRecipients\":[{\"emailAddress\":\"[email protected]\",\"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\":\"[email protected]\",\"sourceArn\":\"arn:aws:ses:us-east-1:someid:identity/[email protected]\",\"sourceIp\":\"127.0.0.1\",\"sendingAccountId\":\"sending.account.id.is.this\",\"messageId\":\"message-id-is-this\",\"destination\":[\"[email protected]\"]}}",
"Timestamp":"2017-04-24T12:58:05.757Z",
"SignatureVersion":"1",
"Signature":"signature.link",
"SigningCertURL":"certificate.link.here",
"UnsubscribeURL":"un.subscribe.link"
}
Le problème est avec l'attribut « Message » qui, au lieu de tenir un objet, est faisant référence à la chaîne d'un objet
contient
"Message":"{\"key\":\"value\"}"
au lieu de
"Message":{"key":"value"}"
ne sont donc pas mis en correspondance Classe de message
temporairement Je résolu ce problème en recevant dans la variable chaîne, puis le convertir
private String Message;
private Message objMessage;
puis
Notification noti = toObject(jsonString, Notification.class);
Message msg = toObject(noti.getMessage(), Message.class);
noti.setObjMessage(msg);
pour la transformation , J'utilise ObjectMapper.readValue (...)
Quelle est la bonne façon de résoudre ce problème?