Skip to content
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

Fix custom data implementation #20

Merged
merged 1 commit into from
Sep 8, 2022

Conversation

afrittoli
Copy link
Contributor

Use a custom unmarshaller and jsonschema tags to fix the implementation of custom data.

CustomData contains the data as follows:

When the content type is "application/json":

  • if the CDEvent is produced via the golang API, the CustomData usually holds an un-marshalled golang interface{} of some type
  • if the CDEvent is consumed and thus un-marshalled from a []byte the CustomData holds the data as a []byte, so that it may be un-marshalled into a specific golang type via the GetCustomDataAs

When the content type is anything else:

  • the content data is always stored as []byte, as the SDK does not have enough knowledge about the data to un-marshal it into a golang type

Extend the interface to include GetCustomDataRaw which always returns a []byte.

Extend the test coverage.

Signed-off-by: Andrea Frittoli andrea.frittoli@gmail.com

Use a custom unmarshaller and jsonschema tags to fix
the implementation of custom data.

`CustomData` contains the data as follows:

When the content type is "application/json":
 - if the CDEvent is produced via the golang API, the
   `CustomData` usually holds an un-marshalled golang
   interface{} of some type
 - if the CDEvent is consumed and thus un-marshalled
   from a []byte the `CustomData` holds the data as a
   []byte, so that it may be un-marshalled into a specific
   golang type via the `GetCustomDataAs`

When the content type is anything else:
 - the content data is always stored as []byte, as the
   SDK does not have enough knowledge about the data to
   un-marshal it into a golang type

Extend the interface to include GetCustomDataRaw which
always returns a []byte.

Extend the test coverage.

Signed-off-by: Andrea Frittoli <andrea.frittoli@gmail.com>
@afrittoli afrittoli merged commit c3f283b into cdevents:main Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant