Skip to main content

PlainSerializer

Plain serializers use a function to modify the output of serialization.

Attributes

AttributeTypeDescription
funccore_schema.SerializerFunctionThe serializer function.
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) = alwaysDetermines 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 PlainSerializer(
func: core_schema.SerializerFunction,
return_type: Any = PydanticUndefined,
when_used: [WhenUsed](../../../serializers/type/serializers/format/whenused.md?sid=serializers_type_serializers_format_whenused) = 'always'
)

Parameters

NameTypeDescription
funccore_schema.SerializerFunctionThe serializer function used to modify the output of serialization.
return_typeAny = PydanticUndefinedThe return type for the function; if omitted, it is 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 (e.g., 'always', 'unless-none', 'json', 'json-unless-none').