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

JsonEventFormatter throws exception when charset is included #216

Closed
cecilphillip opened this issue Jun 27, 2022 · 2 comments · Fixed by #217
Closed

JsonEventFormatter throws exception when charset is included #216

cecilphillip opened this issue Jun 27, 2022 · 2 comments · Fixed by #217

Comments

@cecilphillip
Copy link

cecilphillip commented Jun 27, 2022

In my AspNetCore app, calling HttpContext.Request.ToCloudEventAsync(new JsonEventFormatter()) fails when the datacontenttype property includes the charset. It throws the following exception =>

CloudEvents with a non-JSON datacontenttype can only have string data values.

The following is a sample request that was generated by Dapr.

{
  "id": "126e4073-152e-4abe-b638-d1c2c7a79348",
  "specversion": "1.0",
  "topic": "fulfill.order",
  "pubsubname": "rabbitmqbus",
  "datacontenttype": "application/json; charset=utf-8",
  "source": "website",
  "type": "com.dapr.event.sent",
  "data": {
    "stuff": "value"
  }
}

When the charset is removed, the code works fine.

UPDATE
Just digging around the source seems to be coming from here.

I don't know what the spec says about including charsets. Otherwise, maybe we can use this check instead

ContentType dataContentType = new ContentType(cloudEvent.DataContentType);
if (IsJsonMediaType(dataContentType.MediaType))
@jskeet
Copy link
Contributor

jskeet commented Jun 27, 2022

Thanks, I'll have a look tomorrow.

@jskeet
Copy link
Contributor

jskeet commented Jun 28, 2022

Yes, it looks like the check you've suggested is the right one - that's what we do everywhere else.

jskeet added a commit to jskeet/sdk-csharp that referenced this issue Jun 28, 2022
jskeet added a commit to jskeet/sdk-csharp that referenced this issue Jun 29, 2022
jskeet added a commit that referenced this issue Jun 29, 2022
Fixes #216

Signed-off-by: Jon Skeet <jonskeet@google.com>
jskeet added a commit to jskeet/sdk-csharp that referenced this issue Jun 29, 2022
Changes since 2.3.0:

- Bug fix: ignore the charset when determining the content type for decoding JSON (cloudevents#216)
- Bug fix: make the NuGet package deterministic (cloudevents#175)

Signed-off-by: Jon Skeet <jonskeet@google.com>
@jskeet jskeet mentioned this issue Jun 29, 2022
jskeet added a commit that referenced this issue Jun 29, 2022
Changes since 2.3.0:

- Bug fix: ignore the charset when determining the content type for decoding JSON (#216)
- Bug fix: make the NuGet package deterministic (#175)

Signed-off-by: Jon Skeet <jonskeet@google.com>
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 a pull request may close this issue.

2 participants