Skip to content

Custom serialization / encoders hook for response values #136

Description

@vsdudakov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions