According to the spec, optional attributes, if included in the serialization, MUST be valid values, e.g., for subject:
* Constraints:
* OPTIONAL
* If present, MUST be a non-empty string
Yet, when creating an event and serializing, I'm seeing missing optional values show up as null values in the serialization:
from cloudevents_pydantic.bindings.http import HTTPHandler
from cloudevents_pydantic.events import CloudEvent
event = CloudEvent.event_factory(type='foo', source='bar', data={"answer": 42})
handler = HTTPHandler()
headers, as_json = handler.to_json(event)
print(as_json)
# output:
#
# {"data":{"answer":42},"source":"bar","id":"01K7F9H4T1Q5MVXK9QY4QQQ2WD","type":"foo","specversion":"1.0","time":"2025-10-13T17:22:45.185845+00:00","subject":null,"datacontenttype":null,"dataschema":null}
In the above example, subject, datacontenttype, and dataschema should not appear in the serialization as null.
According to the spec, optional attributes, if included in the serialization, MUST be valid values, e.g., for
subject:Yet, when creating an event and serializing, I'm seeing missing optional values show up as
nullvalues in the serialization:In the above example,
subject,datacontenttype, anddataschemashould not appear in the serialization asnull.