PlainSerializer
Plain serializers use a function to modify the output of serialization.
Attributes
| Attribute | Type | Description |
|---|---|---|
| func | core_schema.SerializerFunction | The serializer function. |
| 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 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
| Name | Type | Description |
|---|---|---|
| func | core_schema.SerializerFunction | The serializer function used to modify the output of serialization. |
| return_type | Any = PydanticUndefined | The 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'). |