-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to get custom json serialization for enums to work #1986
Comments
Also FYI - I've identified that in Line 60 in cdba848
Does it make more sense to check if any custom encoders for the type have been defined first before applying the default for the type? If so, I'm happy to look into contributing a PR to explore that - just wanted to check if my thinking is reasonable first. |
jsonable_encoder
jsonable_encoder
Thanks for the report and for the fix in the PR @viveksunder! 🚀 This is now available in FastAPI |
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
Hi there! We are using pydantic to define our API models and have a use-case where certain fields stored in our database (mongodb) are enums and need to be translated into an API/user friendly representation. We tried the following in order to solve this problem -
class Config
section in the above pydantic base class that will implement serialization for our enums.Output -
Would expect -
Environment
PS - We only recently started using FastAPI at work and we love it!!
The text was updated successfully, but these errors were encountered: