custom_pydantic_encoder
Encodes an object by searching for a matching encoder in the provided type mapping based on the object's method resolution order, falling back to the default Pydantic encoder if no match is found.
def custom_pydantic_encoder(
type_encoders: dict[Any, Callable[[type[Any]], Any]],
obj: Any
) - > Any
Encodes an object by searching for a matching encoder in a provided mapping based on the object's class hierarchy. This function is deprecated and callers should use BaseModel.model_dump instead.
Parameters
| Name | Type | Description |
|---|---|---|
| type_encoders | dict[Any, Callable[[type[Any]], Any]] | A mapping of types to their respective encoding functions used to resolve the appropriate serializer for the object. |
| obj | Any | The object instance to be encoded into a serializable format. |
Returns
| Type | Description |
|---|---|
Any | The serialized representation of the object produced by the matched encoder or the default pydantic_encoder. |