Skip to main content

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

AttributeTypeDescription
funccore_schema.WrapSerializerFunctionThe serializer function to be wrapped.
return_typeAny = PydanticUndefinedThe 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

NameTypeDescription
funccore_schema.WrapSerializerFunctionThe serializer function to be wrapped.
return_typeAny = PydanticUndefinedThe 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) = alwaysDetermines when this serializer should be used (e.g., 'always', 'unless-none', 'json').