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

Serialization of binary data with no content type in JSON format #933

Closed
jskeet opened this issue Jan 14, 2022 · 4 comments
Closed

Serialization of binary data with no content type in JSON format #933

jskeet opened this issue Jan 14, 2022 · 4 comments

Comments

@jskeet
Copy link
Contributor

jskeet commented Jan 14, 2022

I'm trying to adjust the C# JSON serializers to take account of #861 and #881. I'm struggling on a couple of corner cases though, around binary data.

The JSON event format says that a serializer has to distinguish between binary data and non-binary data (to know which data property to populate) and also that the default content type (if otherwise unspecified) should be application/json. The placement of the defaulting (which was my own sentence!) is alongside the "not binary" case.

What does this mean for the structured mode encoded form of a CloudEvent with binary data but no data content type? Should a data content type of application/json be used anyway? Do we expect deserialization to cope with a JSON content type but binary data? (Just assume that the binary data is UTF-8-encoded text?)

It's possible that this kind of corner case doesn't need to be handled the same way by every SDK, of course...

@duglin
Copy link
Collaborator

duglin commented Jan 20, 2022

@jskeet just to make sure I'm following the scenario... are you talking about a CE that looks like:

Content-Type: application/cloudevents+json

{
    "specversion" : "1.0",
    "id": "123",
    "source": "urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66",
    "type" : "com.example.someevent",
    "data_base64": "aGVsbG8gd29ybGQK"
}

If so, are you asking if the receiving SDK is supposed to treat the decoded "aGVsbG8gd29ybGQK" as json? I think the answer is "no" and the SDK shouldn't make any assumptions about it. It should treat it as an array of bytes.

@jskeet
Copy link
Contributor Author

jskeet commented Jan 20, 2022

Nope, that's fine - it's only the data property. I expect I've just misremembered what was agreed, which would be great. Hopefully this can be cleared up really quickly in the meeting.

@jskeet
Copy link
Contributor Author

jskeet commented Jan 20, 2022

Whoops - the above comment was written in a hurry, not noting that it's the wrong issue. (I was thinking of #934.)

Yes, you've got it exactly right, and I agree - I think we should only default to application/json for structured events where data is populated rather than data_base64.

@duglin
Copy link
Collaborator

duglin commented Feb 24, 2022

We agreed to close this on the 2/17 meeting. @jskeet reopen if I got that wrong

@duglin duglin closed this as completed Feb 24, 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

No branches or pull requests

2 participants