java-sparkpost icon indicating copy to clipboard operation
java-sparkpost copied to clipboard

Provide Beans for JSON Response from Relay Webhooks

Open jonturgeon opened this issue 7 years ago • 10 comments

Would be nice to have a set of POJO's that could be used with GSON for decoding the JSON Relay Webhook response.

jonturgeon avatar Apr 21 '17 09:04 jonturgeon

It is a good idea and I am happy to create the POJO's

I assume the user of the POJO's would have the responsibility to run their own HTTP server and instantiate the proper Event class for deserialization?

yepher avatar Apr 21 '17 14:04 yepher

I have a couple of generators that maybe easily adapted to be able to create the POJO's for the Webhook events. They are:

It might be pretty easy to adapt those to generate at least the initial Webhook POJOs

yepher avatar Apr 21 '17 16:04 yepher

Hi Chris, yes to both your questions. My webapp both needs to send and receive emails. The email content is sort of structured data (it is a position reporting system for sailing yachts around the world). I use GSON for other JSON data requests and since you guys already have a Java lib I thought it might be nice to have the POJO's to make getting the relay webhook data in a Java friendly manner.


From: Chris Wilson [email protected] Sent: Friday, April 21, 2017 10:28 AM To: SparkPost/java-sparkpost Cc: jonturgeon; Author Subject: Re: [SparkPost/java-sparkpost] Provide Beans for JSON Response from Relay Webhooks (#62)

It is a good idea and I am happy to create the POJO's

I assume the user of the POJO's would have the responsibility to run their own HTTP server and instantiate the proper Event class for deserialization?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/SparkPost/java-sparkpost/issues/62#issuecomment-296205967, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFkG36V5-3KNBu4evwf7oUvQNfqk2bD7ks5ryLz7gaJpZM4NEGgZ.

jonturgeon avatar Apr 21 '17 16:04 jonturgeon

Hi again, I used this site to get my initial POJO's http://pojo.sodhanalibrary.com/Convert

I fed it the sample response from the relay webhook documentation. Just thought it might be nicer to have a set of POJO's that came from SparkPost to make sure we are not all missing something.


From: Chris Wilson [email protected] Sent: Friday, April 21, 2017 12:26 PM To: SparkPost/java-sparkpost Cc: jonturgeon; Author Subject: Re: [SparkPost/java-sparkpost] Provide Beans for JSON Response from Relay Webhooks (#62)

I have a couple of generators that maybe easily adapted to be able to create the POJO's for the Webhook events. They are:

It might be pretty easy to adapt those to generate at least the initial Webhook POJOs

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/SparkPost/java-sparkpost/issues/62#issuecomment-296238042, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFkG37DXS_uvf_8pIrMV9cTWE3BCYeWSks5ryNi7gaJpZM4NEGgZ.

jonturgeon avatar Apr 21 '17 16:04 jonturgeon

yes, I totally agree with you. It will be nice to have those directly in the SparkPost Library. My comments above are really more about can I do something to help me generate code on other projects I need to do at the same time as I get this implemented in the Java library.

yepher avatar Apr 21 '17 16:04 yepher

I should also note I gladly welcome Pull Requests if this is something you want to take on.

yepher avatar Apr 21 '17 16:04 yepher

Hi again, although I have been whacking away at Java for years, I am completely new to SparkPost and I would not want to put something out with that little bit of knowledge. If you want I can send you my beans so far, they seem to be working for my single test case but they are by no means finished. I also do this development as a bit of a hobby, I left my corporate job 6 years ago to sail around the world, I am doing this website as sort of a way to keep my head in it. I would also be willing to incorporate any beans you create and drop mine and see how they work for me.


From: Chris Wilson [email protected] Sent: Friday, April 21, 2017 12:48 PM To: SparkPost/java-sparkpost Cc: jonturgeon; Author Subject: Re: [SparkPost/java-sparkpost] Provide Beans for JSON Response from Relay Webhooks (#62)

I should also note I gladly welcome Pull Requests if this is something you want to take on.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/SparkPost/java-sparkpost/issues/62#issuecomment-296243727, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFkG327UFbNl_LFSMrR079nAFAT121yTks5ryN3tgaJpZM4NEGgZ.

jonturgeon avatar Apr 21 '17 16:04 jonturgeon

I guess I had better meet you on your Yacht so we can pair program it then ;)

Kidding aside, I would be glad to look at what you have. I will work on adding Webhook events as a first class citizen to the library as you suggested.

yepher avatar Apr 21 '17 17:04 yepher

Attached are my work in progress beans and below is the code I use to populate them

    //Stripes puts the JSON response in the parameter map
    String relayJSON = this.getContext().getRequest().getParameterMap().entrySet().iterator().next().toString();

    //The JSON is a bit wonky, need to be "lenient"
    JsonReader reader = new JsonReader(new StringReader(relayJSON));
    reader.setLenient(true);
    RelayWebhook[] relayWebhooks = new Gson().fromJson(reader, RelayWebhook[].class);

From: Chris Wilson [email protected] Sent: Friday, April 21, 2017 1:08 PM To: SparkPost/java-sparkpost Cc: jonturgeon; Author Subject: Re: [SparkPost/java-sparkpost] Provide Beans for JSON Response from Relay Webhooks (#62)

I guess I had better meet you on your Yacht so we can pair program it then ;)

Kidding aside, I would be glad to look at what you have. I will work on adding Webhook events as a first class citizen to the library as you suggested.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/SparkPost/java-sparkpost/issues/62#issuecomment-296248815, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFkG36WOwQecB3FhWq6BvJm-Vzlixwtjks5ryOKbgaJpZM4NEGgZ.

jonturgeon avatar Apr 21 '17 17:04 jonturgeon

I've created a branch with the initial pass at creating webhook events here

Still need to test them to see if they work.

yepher avatar Apr 21 '17 21:04 yepher