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

add json serialization #124

Merged
merged 2 commits into from
Mar 29, 2018
Merged

add json serialization #124

merged 2 commits into from
Mar 29, 2018

Conversation

duglin
Copy link
Collaborator

@duglin duglin commented Mar 24, 2018

Closes #17

I would actually prefer if we just move this into the main spec itself since its so small, but for now I started out with it being in a separate doc with the assumption that we can decide on whether we want to merge it later.

Signed-off-by: Doug Davis dug@us.ibm.com

@duglin duglin force-pushed the serialize branch 2 times, most recently from 9a6e2c7 to 3d5a1cd Compare March 24, 2018 03:53
Copy link

@SeanFeldman SeanFeldman left a comment

Choose a reason for hiding this comment

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

A few minor comments.

"cloud-events-version": "cloud-events-version value",
"event-id": "event-id value",
"namespace": "namespace value",
"source": {

Choose a reason for hiding this comment

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

@duglin isn't source a URI?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not yet :-)

Choose a reason for hiding this comment

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

Fair enough. Pending #123 🙂

serialization.md Outdated
}
```

Note:

Choose a reason for hiding this comment

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

nitpicking - sais Note, but these are notes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

serialization.md Outdated
```

Note:
- the use of whitespace is not significant

Choose a reason for hiding this comment

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

Capitalize?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@duglin duglin force-pushed the serialize branch 2 times, most recently from 349dab1 to c4fd2d5 Compare March 24, 2018 14:47
serialization.md Outdated
@@ -0,0 +1,43 @@
# CloudEvents Serialization Profile - Version 0.1

This document specified how a CloudEvent is to be serialized into certain
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be applied here? s/specified/specifies/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed the "specified" typo. What did you mean by "should this applied here?" ?

}
```

Notes:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a comment about extra fields in the serialized data? Such as:

- It is undefined whether extra fields are passed along or removed depending on the usage role and implementation. Those fields are best placed in the extensions map.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I expanded on the thought a little - see what you think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the update. LGTM.

}
```

Notes:
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the update. LGTM.

spec.md Outdated
@@ -26,6 +26,11 @@ Enter CloudEvents, a specification for describing event data in a common way.
CloudEvents seeks to ease event declaration and delivery across services,
platforms and beyond.

The [Serialization Profile](serialization.md) specified how to
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be better as "specifies". (Or am I being too tense?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, you're right - just a disconnect between the brain and fingers.


```
{
"cloud-events-version": "cloud-events-version value",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious whether it would be more useful to use valid fake values rather than prose in quotes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I struggled with this because if we put fake values in there then we need something to say "property X from the spec goes into json property 'x'". While in many cases it should be really really obvious, I felt that a spec should be more explicit about it. If all we cared about was JSON I actually would have proposed that we have the serialization of each property next to its definition in the spec itself. But I didn't want to assume everyone would be ok with JSON getting special treatment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@inlined I added an example to try to address your concern. See if that helps.

"extensions": {
... extensions values ...
},
"data": ... data value ...
Copy link
Contributor

@inlined inlined Mar 28, 2018

Choose a reason for hiding this comment

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

As an FYI: though Google&Firebase started out with a model like this where all context is at the top level with one magic field called "data", we generally considered this to be a mistake. Many languages have better ways to expose context (e.g. Golang's Context.context, or JavaScript's variadic parameter system) so we are migrating to a world where data & context are exposed separately/natively our runtimes. Alpha testers have given very positive feedback for this because it allows any existing function(SomeNativeType) to be a CloudFunction<SomeNativeType>.

To match this, the REST JSON is being migrated to a two-field JSON object with {"context", "data"}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could live with that. What do other people think?

Choose a reason for hiding this comment

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

@inlined would extensions be under context or another sibling at the root level?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@inlined where would "could-events-version" go? I can see it being useful as a top-level thing since we may choose to rename data or context in a future version, but I can also see a need for that info to be passed downstream so people know how to interpret the context attributes based on our spec's version number.

I do want to explore this option, it feels cleaner - would make for a great follow-on PR

Copy link
Contributor

Choose a reason for hiding this comment

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

@duglin I agree with @inlined that context and data should be on the same level as he suggested.

One more thing:
Do we need rules how to encode data, if the content-type is something binary or text/xml?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

would that be something that the definition of the content-type (e.g. json spec) would need to define?

Copy link
Contributor

Choose a reason for hiding this comment

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

afaik json spec does not cover this explicitly. Most people seem to base64 encode data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea, I did a quick search too and didn't find a lot. I guess we could offer some recommendations...

Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly I don't have the practical experience with content-type and cloud-events-version that I do with the other fields. Here's my first SWAG:

  • In my opinion, content-type is/should be meta to the whole spec (why are we dictating the content type within a payload that's already explicitly JSON encoded?). This should be dictated in the transport layer, not the encoding layer.
  • cloud-events-version looks cleanest at the top level in JSON though if it's going to show up in the programming model it might be easier to put it in context.
  • I have the strong opinion (weakly held) that extensions should be in context. The developer is likely to depend on these extensions and they should be easily accessible.

Copy link
Contributor

Choose a reason for hiding this comment

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

@inlined My understanding is that this PR is about how to package an arbitrary cloudevent into json. I was just wondering what happens if the content-type (the context attribute) is text/xml or image/png. The result is supposed to be a valid json object. So data would need to be encoded somehow. I don't see how this can be delegated to another layer. For events that use json for their data section, there is of course no need for encoding.

Signed-off-by: Doug Davis <dug@us.ibm.com>
Signed-off-by: Doug Davis <dug@us.ibm.com>
@duglin
Copy link
Collaborator Author

duglin commented Mar 29, 2018

Added an example and one line to make it clear that optional fields are still optional, but if present then they MUST adhere to the rules defined. I think it was implied before but now its explicitly stated.

@ultrasaurus
Copy link
Contributor

This will have to be modified to be consistent with changed accepted today

@duglin
Copy link
Collaborator Author

duglin commented Mar 29, 2018

Approved on 3/29 call

@duglin duglin merged commit 1db322f into cloudevents:master Mar 29, 2018
@duglin duglin deleted the serialize branch March 31, 2018 12:14
@duglin duglin mentioned this pull request Mar 31, 2018
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.

None yet

6 participants