Skip to content

Conversation

@slinkydeveloper
Copy link
Member

@slinkydeveloper slinkydeveloper commented Nov 19, 2020

Fix #285

  • Now, across all the different interfaces we have, CloudEventDataMapper cannot be null
  • Cleanup of all mapper != null and replaced with CloudEventDataMapper.identity()
  • Fixed all the missing wildcards

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>
@slinkydeveloper slinkydeveloper added the enhancement New feature or request label Nov 19, 2020
@slinkydeveloper slinkydeveloper added this to the 2.0.0.CR1 milestone Nov 19, 2020
Copy link

@eamonnmcmanus eamonnmcmanus left a 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>
@slinkydeveloper slinkydeveloper changed the title Introduce CloudEventDataMapper.NOOP Introduce CloudEventDataMapper.identity() Nov 19, 2020
/**
* No-op identity mapper which can be used as default when no mapper is provided.
*/
static CloudEventDataMapper<? extends CloudEventData> identity() {

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;
    }

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.

Copy link
Member Author

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.

Copy link
Member Author

@slinkydeveloper slinkydeveloper Nov 19, 2020

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?

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.

Copy link
Member Author

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>
@slinkydeveloper slinkydeveloper merged commit baf3b56 into cloudevents:master Nov 19, 2020
@slinkydeveloper slinkydeveloper deleted the issues/285 branch November 19, 2020 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't allow null CloudEventDataMapper

2 participants