You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, if an implementation determines that the type of the data attribute is Binary or String, it MUST inspect the datacontenttype attribute to determine whether it is indicated that the data value contains JSON data.
If the datacontenttype value is either "application/json" or any media type with a structured +json suffix, the implementation MUST translate the data attribute value into a JSON value, and set the data attribute of the envelope JSON object to this JSON value.
If I'm reading the spec correctly, it looks like the SDK should serialize stringified JSON in the data attribute. In other words, I would expect this to work:
constv03=require("cloudevents-sdk/v03");constdata={"so": "scare"};constce=v03.event.id('4e4cfbd6-d542-4235-9e80-99d2df62abee').source('com.example.whatever').type('something').dataContentType("application/json").data(JSON.stringify(data))// <-- stringified json data goes in.format();constceData=ce.getData();console.log(ceData.so);// <-- this breaks, getData returned the stringified JSON, not an object.
I wrote a sample test (joshwlewis@19cc9f3), if it's more useful than my untested example. It fails with:
CloudEvents Spec v0.3
The Constraints check
'data'
1) should convert data with stringified json to a json object
0 passing (8ms)
1 failing
1) CloudEvents Spec v0.3
The Constraints check
'data'
should convert data with stringified json to a json object:
AssertionError: expected '{"much":"wow"}' to equal { much: 'wow' }
at Context.it (test/spec_0_3_tests.js:209:41)
The text was updated successfully, but these errors were encountered:
@joshwlewis, after reading and talking with some fellows, we conclude that's right for incoming events, that needs to be unmarshaled. But, for the outcoming event, created by the v03.event()... the type will be as-is, no parsing at all.
If we parse a string to json in the v03.event().., we will ending to marshall a json object, not a string.
Is that makes sense to you?
ps: even at this moment, the unmarshaller does not parse the string into json object for the incoming events.
In the v0.3 spec for JSON format section about Special Handling of the "data" Attribute, it says:
If I'm reading the spec correctly, it looks like the SDK should serialize stringified JSON in the data attribute. In other words, I would expect this to work:
I wrote a sample test (joshwlewis@19cc9f3), if it's more useful than my untested example. It fails with:
The text was updated successfully, but these errors were encountered: