Skip to content

Conversation

@slinkydeveloper
Copy link
Member

@slinkydeveloper slinkydeveloper commented Nov 10, 2020

This PR adds a new method to CloudEventUtils, called mapData(event, mapper) (implemented by default), to improve the user experience with mappers. Now we finally have a good user experience for data: users can now safely map event payloads to business objects without casting and without any knowledge of the sdk itself:

MyPojo myPojo = mapData(event, PojoCloudEventDataMapper.from(objectMapper, new TypeReference<MyPojo>() {})) // PojoCloudEventDataMapper<MyPojo>
  .getValue();

(note: this example is using json mapper which is proposed in another pr independent from this one)

To make this possible, I also generified the return value of CloudEventDataMapper

Signed-off-by: Francesco Guardiani francescoguard@gmail.com

Added toData(CloudEventDataMapper) method to map the data

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
@slinkydeveloper slinkydeveloper added the enhancement New feature or request label Nov 10, 2020
@olegz
Copy link
Contributor

olegz commented Nov 10, 2020

As it was debated many times before this change violates the consistency and simplicity of the core interface.
So -1

Tagging @n3wscott @duglin as I already have an open complaint about a PR being merged with no consensus reached - #250 (comment)

@slinkydeveloper
Copy link
Member Author

Related to #258

@johanhaleby
Copy link
Contributor

My feeling is that serialization/conversion should not be a part of the interface, it's a separate concern.

It would be OK if it was an extension function provided by the serialization library/module.

@slinkydeveloper
Copy link
Member Author

@johanhaleby Except we don't have extensions in java 😄 How about moving to some utils class, like CloudEventUtils in core?

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
@slinkydeveloper
Copy link
Member Author

Moved, now it should be better

@slinkydeveloper slinkydeveloper changed the title CloudEvent.toData(mapper) CloudEventUtils.mapData(event, mapper) Nov 10, 2020
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
@aliok
Copy link

aliok commented Nov 10, 2020

This seems like the next natural step after the previous improvements.
Makes more sense with #258.

/lgtm

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
@slinkydeveloper slinkydeveloper mentioned this pull request Nov 10, 2020
@slinkydeveloper slinkydeveloper added this to the 2.0.0-milestone5 milestone Nov 10, 2020
Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@slinkydeveloper slinkydeveloper merged commit 3bd9a69 into cloudevents:master Nov 11, 2020
@slinkydeveloper slinkydeveloper deleted the toData branch November 11, 2020 07:48
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.

5 participants