Tenho um json que estou tentando recuperar algumas tags:
{“notificationType”:“Bounce”,“bounce”:{“bounceType”:“Permanent”,“bounceSubType”:“Suppressed”,“bouncedRecipients”:[{“emailAddress”:“[email removido]”,“action”:“failed”,“status”:“5.1.1”,“diagnosticCode”:"Amazon SES has suppressed sending to this address because it has a recent history of bouncing as an invalid address. For more information about how to remove an address from the suppression list, see the Amazon SES Developer Guide: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/remove-from-suppressionlist.html "}],“timestamp”:“2020-03-22T12:48:46.997Z”,“feedbackId”:“010001710249db53-1742f91f-40c4-4426-bb8a-1ad27cbc4823-000000”,“reportingMTA”:“dns; amazonses.com”},“mail”:{“timestamp”:“2020-03-22T12:48:46.997Z”,“source”:“[email removido]”,“sourceArn”:“arn:aws:ses:us-east-1:019128763192:identity/[email removido]”,“sourceIp”:“152.250.204.219”,“sendingAccountId”:“019128763192”,“messageId”:“010001710249da16-a642b7e4-45fa-4702-bd05-692f49bbdce9-000000”,“destination”:[“[email removido]”]}}
Bom dia, eu costumo usar uma api do google para fazer parse de objetos em json. Segue exemplo:
<dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId><version>2.8.6</version></dependency>publicstaticvoidmain(String[]args){Stringjson="{\"notificationType\":\"Bounce\","+"\"bounce\":{"+"\"bounceType\":\"Permanent\","+"\"bounceSubType\":\"Suppressed\","+"\"bouncedRecipients\":"+"[{"+"\"emailAddress\":\"[email removido]\","+"\"action\":\"failed\","+"\"status\":\"5.1.1\","+"\"diagnosticCode\":\"Amazon SES has suppressed sending to this address because it has a recent history of bouncing as an invalid address. For more information about how to remove an address from the suppression list, see the Amazon SES Developer Guide: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/remove-from-suppressionlist.html \""+"}],"+"\"timestamp\":\"2020-03-22T12:48:46.997Z\","+"\"feedbackId\":\"010001710249db53-1742f91f-40c4-4426-bb8a-1ad27cbc4823-000000\","+"\"reportingMTA\":\"dns; amazonses.com\""+"},"+"\"mail\":{"+"\"timestamp\":\"2020-03-22T12:48:46.997Z\","+"\"source\":\"[email removido]\","+"\"sourceArn\":\"arn:aws:ses:us-east-1:019128763192:identity/[email removido]\","+"\"sourceIp\":\"152.250.204.219\","+"\"sendingAccountId\":\"019128763192\","+"\"messageId\":\"010001710249da16-a642b7e4-45fa-4702-bd05-692f49bbdce9-000000\","+"\"destination\":[\"[email removido]\"]"+"}}";Gsongson=newGson();Notificationnotification=gson.fromJson(json,Notification.class);System.out.println(ZonedDateTime.ofInstant(notification.getBounce().getTimestamp().toInstant(),ZoneId.of("GMT")));System.out.println(notification);System.out.println(json);System.out.println(gson.toJson(notification));}@Data@NoArgsConstructor@AllArgsConstructorpublicclassNotification{privateStringnotificationType;privateBouncebounce;privateMailmail;}@Data@NoArgsConstructor@AllArgsConstructorpublicclassBounce{privateStringbounceType;privateStringbounceSubType;privateList<BouncedRecipients>bouncedRecipients;//yyyy-MM-dd'T'HH:mm:ss.SprivateDatetimestamp;privateStringfeedbackId;privateStringreportingMTA;}@Data@NoArgsConstructor@AllArgsConstructorpublicclassBouncedRecipients{privateStringemailAddress;privateStringaction;privateStringstatus;privateStringdiagnosticCode;}@Data@NoArgsConstructor@AllArgsConstructorpublicclassMail{//yyyy-MM-dd'T'HH:mm:ss.SprivateDatetimestamp;privateStringsource;privateStringsourceArn;privateStringsourceIp;privateStringsendingAccountId;privateStringmessageId;privateList<String>destination;}
Depois de feito o mapeamento do json em classes basta usar a biblioteca para fazer o parse.