Skip to content

How to export by Pydantic models by alias #1458

Answered by cofin
tspanos asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @tspanos, thanks for bringing this up. This is something we should probably make a bit more clear. We don't export by alias when using pydantic. If you'd like to override this behavior, it's really simple. Here is how I'm doing it in my current application.

let me know if this helps!

    def _base_model_encoder(value: BaseModel) -> dict[str, Any]:
        return value.dict(by_alias=True)

    app = Starlite(
       ...
        type_encoders={ BaseModel: _base_model_encoder},
       
    )

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cofin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Question This is a question and further information is requested
2 participants
Converted from issue

This discussion was converted from issue #1436 on April 07, 2023 16:51.