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!: Properly handle data when the content-type indicates JSON #57

Merged
merged 1 commit into from
Jun 26, 2021

Conversation

dazuma
Copy link
Member

@dazuma dazuma commented Jun 25, 2021

Previously, if the datacontenttype indicated JSON, the HTTP Binary decoder would not parse it but create CE objects containing the JSON-formatted string. This was inconsistent with the behavior of JSON structured decoding, and also caused incorrect round-tripping of JSON data content if the data was a JSON string rather than a JSON object.

This PR:

  • Fixes the HTTP-Binary decoder so it parses JSON content-types and exposes the data attribute as a JSON value.
  • Ensures that a CE with a string-valued data attribute and a JSON content-type, is semantically treated as a JSON string, and is "serialized" as such when encoding as HTTP-Binary.
  • Updates the HTTP-Binary decoder so it raises the new CloudEvents::NotCloudEventError (rather than returning nil) if given an HTTP request that does not appear to be a CloudEvent. This is a breaking change.

It also makes some adjustments to the format interface, standardizing and documenting the interface, transferring responsibility for content type handling to the format object, and adjusting JsonFormat to conform. It also makes some lower-level conversion methods in HttpBinding private. These involve breaking changes to some public interfaces, but not ones that are expected to be in widespread use at this point.

See also cloudevents/spec#558

Signed-off-by: Daniel Azuma <dazuma@google.com>
@dazuma dazuma merged commit 1c7cae8 into cloudevents:main Jun 26, 2021
@dazuma dazuma deleted the pr/json-format branch June 26, 2021 21:58
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