Summary
Provide an extension point so users can control how their own field types are serialized in API responses (e.g. Decimal, enums, custom datetime formats, domain value objects).
Evidence from forks
alex-averin/fastadmin implemented this (compare):
- Adds a
CUSTOM_ENCODERS registry (fastadmin/api/encoders.py):
CUSTOM_ENCODERS: dict[typing.Any, typing.Callable[[typing.Any], typing.Any]] = {}
- Wires it into every FastAPI response endpoint via
jsonable_encoder(..., custom_encoder=CUSTOM_ENCODERS) (me, list_objs, get, add, change).
Commit: "Add custom encoders for fastapi".
Proposal
Expose a documented, ORM-agnostic hook for registering custom encoders (per type), applied consistently across all read/write endpoints. This also gives users a clean way to solve the datetime-format issue (#135).
Filed from an analysis of all forks of this repo.
Summary
Provide an extension point so users can control how their own field types are serialized in API responses (e.g.
Decimal, enums, custom datetime formats, domain value objects).Evidence from forks
alex-averin/fastadmin implemented this (compare):
CUSTOM_ENCODERSregistry (fastadmin/api/encoders.py):jsonable_encoder(..., custom_encoder=CUSTOM_ENCODERS)(me,list_objs,get,add,change).Commit: "Add custom encoders for fastapi".
Proposal
Expose a documented, ORM-agnostic hook for registering custom encoders (per type), applied consistently across all read/write endpoints. This also gives users a clean way to solve the datetime-format issue (#135).
Filed from an analysis of all forks of this repo.