Pydantic · Function
model_serializer
@model_serializer customizes how a whole Pydantic model is serialized. Use plain mode to replace the output, or wrap mode to modify Pydantic's normal output.
Last updated
Syntax
def model_serializer(f: _ModelPlainSerializerT, /) -> _ModelPlainSerializerT
def model_serializer(*, mode: Literal['wrap'], when_used: WhenUsed = 'always', return_type: TypeForm[Any] = ...) -> Callable
def model_serializer(*, mode: Literal['plain'] = ..., when_used: WhenUsed = 'always', return_type: TypeForm[Any] = ...) -> CallableIn-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.
SubscribeRelated
field_serializerPlainSerializerWrapSerializerSerializationInfoSerializerFunctionWrapHandlerBaseModel.model_dump