On Tue, May 28, 2024 at 11:46 AM Left Right via Python-list <python-list@python.org> wrote:
Most Python objects aren't serializable into JSON. Pydantic isn't
special in this sense.
What can you do about this? -- Well, if this is a one-of situation,
then, maybe just do it by hand?
If this is a recurring problem: json.dumps() takes a cls argument that
will be used to do the serialization. Extend json.JSONEncoder and
implement the encode() method for the encoder class you are passing. I
believe that the official docs have some information about this too.
Yeah, I know I can do this, but I seem to recall reading that pydantic handled serialization. Guess not.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 452 |
Nodes: | 16 (0 / 16) |
Uptime: | 96:36:17 |
Calls: | 9,272 |
Calls today: | 5 |
Files: | 13,511 |
Messages: | 6,069,873 |