Skip to content

Custom response breaks for Starlite >= 1.48.0 #1072

Closed Answered by provinzkraut
david-welch asked this question in Q&A
Discussion options

You must be logged in to vote

Response.serializer is a classmethod, so you need to add the @classmethod decorator.

However, there are easier methods to solve this! Take a look at the custom responses examples in the docs. You can add a type_encoders dictionary on any layer of the application, so a minimal implementation would look something like this:

from starlite import Starlite
# add your type imports here

beanie_encoders = {
    PydanticObjectId: str,
    Link: lambda link: link.to_dict().get("id"),
    Int64: int,
}

app = Starlite(..., type_encoders=beanie_encoders)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@david-welch
Comment options

Answer selected by david-welch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants