Extra
This class manages the configuration and state for the serialization process, holding references to the Python interpreter and specific serialization modes. It encapsulates various filtering flags, such as excluding defaults or none values, and provides options for handling aliases, computed fields, and polymorphic serialization. Additionally, it supports custom fallback logic and context-specific data to be used during the transformation of objects.
Attributes
| Attribute | Type | Description |
|---|---|---|
| py | Python | Reference to the Python interpreter instance used for managing object lifetimes and interactions during serialization. |
| mode | [SerMode](sermode.md?sid=serializers_extra_sermode) | The serialization mode determining whether the output should be optimized for Python objects or JSON-compatible formats. |
| ob_type_lookup | [ObTypeLookup](../ob/type/obtypelookup.md?sid=serializers_ob_type_obtypelookup) | A static lookup table used to identify and map Python object types to their corresponding serialization logic. |
| by_alias | bool | Determines whether to use the field's alias name instead of the attribute name during serialization. |
| exclude_unset | bool | Whether to omit fields from the serialized output that were not explicitly set during model initialization. |
| exclude_defaults | bool | Whether to omit fields from the serialized output if their values are equal to their defined default values. |
| exclude_none | bool | Whether to omit fields from the serialized output that have a value of None. |
| exclude_computed_fields | bool | Whether to omit properties decorated as computed fields from the final serialized representation. |
| round_trip | bool | Whether to ensure serialization is performed in a way that supports full reconstruction of the original object. |
| serialize_unknown | bool | Whether to attempt serialization of object types that are not explicitly recognized by the schema. |
| fallback | PyAny | An optional Python callable used to handle objects that the serializer does not know how to process. |
| serialize_as_any | bool | Whether to serialize objects based on their runtime type rather than their declared type hint. |
| polymorphic_serialization | bool | Whether polymorphic_serialization is globally enabled / disabled for this serialization process |
| context | PyAny | An optional Python object containing arbitrary state or configuration passed through to custom serialization logic. |
Constructor
Signature
def Extra(
py: Python,
mode: [SerMode](sermode.md?sid=serializers_extra_sermode),
ob_type_lookup: [ObTypeLookup](../ob/type/obtypelookup.md?sid=serializers_ob_type_obtypelookup),
by_alias: Option< bool > = null,
exclude_unset: bool = null,
exclude_defaults: bool = null,
exclude_none: bool = null,
exclude_computed_fields: bool = null,
round_trip: bool = null,
serialize_unknown: bool = null,
fallback: Option< Bound< PyAny > > = null,
serialize_as_any: bool = null,
polymorphic_serialization: Option< bool > = null,
context: Option< Bound< PyAny > > = null
) - > [Extra](../../validators/mod/extra.md?sid=validators_mod_extra)
Parameters
| Name | Type | Description |
|---|---|---|
| py | Python | The Python interpreter instance. |
| mode | [SerMode](sermode.md?sid=serializers_extra_sermode) | The serialization mode to be used. |
| ob_type_lookup | [ObTypeLookup](../ob/type/obtypelookup.md?sid=serializers_ob_type_obtypelookup) | A reference to the object type lookup table. |
| by_alias | Option< bool > = null | Whether to use field aliases during serialization. |
| exclude_unset | bool = null | Whether to exclude fields that are not set. |
| exclude_defaults | bool = null | Whether to exclude fields with default values. |
| exclude_none | bool = null | Whether to exclude fields with None values. |
| exclude_computed_fields | bool = null | Whether to exclude computed fields. |
| round_trip | bool = null | Whether to enable round-trip serialization support. |
| serialize_unknown | bool = null | Whether to serialize unknown fields. |
| fallback | Option< Bound< PyAny > > = null | An optional fallback handler for unknown types. |
| serialize_as_any | bool = null | Whether to serialize objects as the 'Any' type. |
| polymorphic_serialization | Option< bool > = null | Whether polymorphic serialization is globally enabled or disabled. |
| context | Option< Bound< PyAny > > = null | Optional context data for the serialization process. |