Re: Serializing pydantic enums

2024-05-29 Thread Mats Wichmann via Python-list
On 5/29/24 13:27, Larry Martell via Python-list wrote: On Tue, May 28, 2024 at 11:46 AM Left Right via Python-list 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

Re: Serializing pydantic enums

2024-05-29 Thread Larry Martell via Python-list
On Wed, May 29, 2024 at 12:27 PM Larry Martell wrote: > > On Tue, May 28, 2024 at 11:46 AM Left Right via Python-list > 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

Re: Serializing pydantic enums

2024-05-29 Thread Larry Martell via Python-list
On Tue, May 28, 2024 at 11:46 AM Left Right via Python-list 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

Re: Serializing pydantic enums

2024-05-28 Thread Left Right via Python-list
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

Serializing pydantic enums

2024-05-28 Thread Larry Martell via Python-list
Just getting started with pydantic. I have this example code: class FinishReason(Enum): stop = 'stop' class Choice(BaseModel): finish_reason: FinishReason = Field(...) But I cannot serialize this: json.dumps(Choice(finish_reason=FinishReason.stop).dict()) *** TypeError: Object of type