-
Notifications
You must be signed in to change notification settings - Fork 166
Introduce CloudEventDataMapper.identity() #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce CloudEventDataMapper.identity() #286
Conversation
Cleanup of all mapper != null and replaced with CloudEventDataMapper.NOOP Fixed all the missing wildcards Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
eamonnmcmanus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! That's exactly what I had in mind. Just one small suggestion.
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
| /** | ||
| * No-op identity mapper which can be used as default when no mapper is provided. | ||
| */ | ||
| static CloudEventDataMapper<? extends CloudEventData> identity() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I hadn't noticed the problem with the type bound. I guess this is fine. The bound extends CloudEventData is redundant because it's already present in the declaration of CloudEventDataMapper. In other words just <?> would have the same effect.
If the wildcard does cause problems it's possible to restore the <R> solution using casts:
@SuppressWarnings("unchecked")
static <R extends CloudEventData> CloudEventDataMapper<R> identity() {
return d -> (R) d;
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way this suggests to me that the types here aren't really sound. This is saying that you can take any CloudEventData and convert it to MyCloudEventData with an identity transformation. I wonder if the <R> parameter is really useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the parameter is really useful.
I can show you a use case when this is useful: https://github.com/cloudevents/sdk-java/pull/288/files#diff-d32fb9f764f16209b2cb69f1239b4309975c5601affe825cc4ff9428eca42d1bR52
The CloudEventDataMapper can be used directly by the user, when interacting with the event. In this use case, invoking the mapper helper, you get back the concrete type extending CloudEventData. Or you can use the mapper inside a CloudEventReader or EventFormat, and you won't care about the returned concrete type at all because in any case, you assign back to a CloudEventData.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe in the identity case R should just be CloudEventData? like:
static CloudEventDataMapper<CloudEventData> identity() {
return d -> d;
}In any case, we will use identity (at least inside the sdk) only for defaulting CloudEventDataMapper inside EventFormats and CloudEventReaders?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! That's obviously the right thing to do. Sorry I made it more complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok can you review it again? If it's fine, i'm gonna merge it 😄
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Fix #285
CloudEventDataMappercannot be null