jsontypedef / json-typedef-codegen

A CLI tool that generates code from JSON Typedef schemas
https://jsontypedef.com/docs/tools/jtd-codegen
MIT License
160 stars 31 forks source link

Python datetime serialisation/deserialisation not working correctly without timezone #71

Open cimpeanvasile opened 1 year ago

cimpeanvasile commented 1 year ago

There seems to be an issue with serialising and deserialising datetimes for python generated dataclasses. This example fails with ValueError: ('Invalid RFC3339 date/time', '2023-01-01T00:00:00'):

some_dataclass = SomeDataclass(some_time=datetime(2023, 1, 1, 0, 0, 0))
json_data = some_dataclass.to_json_data()
some_dataclass = SomeDataclass.from_json_data(json_data)

It seems to be because the serialising to json for datetime is just datetime.isoformat(), which will return '2023-01-01T00:00:00' for the mentioned value. This will then fail the check in the generated dataclass' _parse_rfc3339 function.