WrapSerializer
Wrap serializers receive the raw inputs along with a handler function that applies the standard serialization logic, and can modify the resulting value before returning it as the final output of serialization.
Attributes
| Attribute | Type | Description |
|---|---|---|
| func | core_schema.WrapSerializerFunction | The serializer function to be wrapped. |
| return_type | Any = PydanticUndefined | The return type for the function. If omitted it will be inferred from the type annotation. |
| when_used | [WhenUsed](../../../serializers/type/serializers/format/whenused.md?sid=serializers_type_serializers_format_whenused) = 'always' | Determines when this serializer should be used. Accepts a string with values 'always', 'unless-none', 'json', and 'json-unless-none'. Defaults to 'always'. |
Constructor
Signature
def WrapSerializer(
func: core_schema.WrapSerializerFunction,
return_type: Any = PydanticUndefined,
when_used: [WhenUsed](../../../serializers/type/serializers/format/whenused.md?sid=serializers_type_serializers_format_whenused) = always
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| func | core_schema.WrapSerializerFunction | The serializer function to be wrapped. |
| return_type | Any = PydanticUndefined | The return type for the function; inferred from type annotations if omitted. |
| when_used | [WhenUsed](../../../serializers/type/serializers/format/whenused.md?sid=serializers_type_serializers_format_whenused) = always | Determines when this serializer should be used (e.g., 'always', 'unless-none', 'json'). |