Skip to content

Event data field is not marshaled as a JSON value but string when DataContentType=application/cloudevents+json #1161

@alank-ps

Description

@alank-ps

According to https://github.com/cloudevents/spec/blob/main/cloudevents/formats/json-format.md#311-payload-serialization,

If the datacontenttype declares the data to contain JSON-formatted content, a JSON serializer MUST translate the data value to a JSON value, and use the member name data to store it inside the JSON representation. The data value MUST be stored directly as a JSON value, rather than as an encoded JSON document represented as a string. An implementation MAY fail to serialize the event if it is unable to translate the runtime value to a JSON value.

However, the WriteJson() function in in event_marshal.go only consider ApplicationJSON and TextJSON (and also default empty) data content type as isJson=true.

https://github.com/cloudevents/sdk-go/blob/main/v2/event/event_marshal.go#L153

It results in writing "structured" type ApplicationCloudEventsJSON as a string, not a JSON value.

https://github.com/cloudevents/sdk-go/blob/main/v2/event/event_marshal.go#L172

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions