to_dict() does not convert enums to strings
See original GitHub issueAs resolved in #51, python enums can be used with dataclasses-json and I have successfully tried that, using the to_json()
and from_json()
methods.
However, with to_dict()
, enum values appear to be untouched, hence the resulting dictionary is not JSON serializable. I assume that this is not the intended behavior, as according to the API docs, to_dict()
should return a JSON-compatible dict.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Pydantic enum field does not get converted to string
I am trying to restrict one field in a class to an enum. However, when I try to get a dictionary out of...
Read more >Enum.ToString Method (System) - Microsoft Learn
This method overload is obsolete; use ToString(). ToString(). Converts the value of this instance to its equivalent string representation.
Read more >Three Methods to Convert Strings into Enums in C# - Ivan Kahl
Method 1: Enum. NET. It allows you to convert a string into an enum by matching the given string to the enum item...
Read more >Convert an enum to a list in C# | Techie Delight
Get a list of Enum members. The idea is to use the Enum.GetValues() method to get an array of the enum constants' values....
Read more >ASP.NET Core: Converting C# enums to JavaScript
GetValues() returns Array and Array doesn't have LINQ extensions available we ... and this method returns enum as JavaScript object string.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
you have to do
foo.to_dict(encode_json=True)
I also have this issue with
to_json()
, which doesn’t have anencode_json
parameter. What I ended up doing was