Declare CloudEvent generic to allow automatic payload deserialization using Jackson#591
Conversation
eb8f645 to
c7dd270
Compare
| //Creating the DaprClient: Using the default builder client produces an HTTP Dapr Client | ||
| try (DaprClient client = new DaprClientBuilder().build()) { | ||
| for (int i = 0; i < NUM_MESSAGES; i++) { | ||
| CloudEvent cloudEvent = new CloudEvent(); |
There was a problem hiding this comment.
Is this required? Changes must be backwards compatible, which means that code without generics should still work as-is.
There was a problem hiding this comment.
It is not required, in the sense that it will also work without specifying the generic type. You can see that in the PubSubIT, where even the published message is declared without a generic type. On the consuming side, it can be consumed as a CloudEvent or as a CloudEvent<PubSubIT.MyObject>. See SubscriberController for an example of that.
I thought it would make sense to update the documentation. Since this file is in the examples/ folder, I consider it part of the documentation, and hence decided to update it.
artursouza
left a comment
There was a problem hiding this comment.
LGTM. I can merge this after ITs are passing. Please, take a look.
Rather than returning `null` when no messages are present for a topic.
Welp, must've missed that. Apologies. I've updated the helper REST controller to always return a list, even if it's empty, rather than returning |
Codecov Report
@@ Coverage Diff @@
## master #591 +/- ##
=========================================
Coverage 81.03% 81.03%
Complexity 991 991
=========================================
Files 88 88
Lines 3042 3042
Branches 332 332
=========================================
Hits 2465 2465
Misses 409 409
Partials 168 168
Continue to review full report at Codecov.
|
|
Hi @artursouza, was it on purpose, that this issue has not been added to any milestone? I was happily supprised when I realised, that with 1.3.0 we now have a typed CloudEvent :-) Are there more issues released by 1.3.0 or 1.3.1? |
… using Jackson (dapr#591) * Declare CloudEvent generic * Fix timestamp in logging * Declare Spring Boot version once * Simplify administration of received events * Update docs * Always return a list, even if it's empty Rather than returning `null` when no messages are present for a topic. Signed-off-by: zjx244729 <zjx244729@alibaba-inc.com>
Description
I've made the
CloudEventclass a generic class, meaning its instance variabledatais now of a generic type<T>. This allows Spring Boot controller methods to accept an argumentCloudEvent<MyPayload>, which will make the code inside that controller method a lot easier as theMyPayloadobject will automatically be populated from a JSON payload.At runtime, this generic type
<T>resorts toObject, which I believe makes this backward compatible. The existing tests are all green which supports this claim.Also, I did a small refactoring in the Spring Boot Rest Controller that the
PubSubITuses to make it easier to maintain.Issue reference
This closes #576.
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: