Open mrossi-kmx opened 1 year ago
Hey @mrossi-kmx,
Thx for opening the issue. And yes, currently JSON behavior is not configurable. The Pydantic model is able to perform the conversion while it uses a separate JSON serialization approach.
This should be improved all over the SDK as I mentioned here.
Thanks for your response @xSAVIKx! Do you/others have a recommendation for what to do with datetimes in the meantime? Just encode them as strings?
Thanks for your response @xSAVIKx! Do you/others have a recommendation for what to do with datetimes in the meantime? Just encode them as strings?
That's probably the best approach here. Or you can use Pydantic wrapper if that's ok
Expected Behavior
The CloudEvent model, like Pydantic's BaseModel, can serialize of
datetime
properties to strings in the.json()
function.Actual Behavior
The CloudEvent model raises a
ValueError
from the standard library'sjson.dumps
function when.json()
is called on a model containingdatetime
properties in thedata
field.Alternatively, if this is intentional behavior, it would be helpful to have some guidance around what the expected usage is when users want to have dates or timestamps in their CloudEvent data.
Steps to Reproduce the Problem
data
argument is adatetime
instance..json()
on the CloudEvent instanceFor example:
By contrast, Pydantic's BaseModel is able to encode datetime properties:
Specifications