Skip to main content

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

AttributeTypeDescription
pyPythonReference 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_aliasboolDetermines whether to use the field's alias name instead of the attribute name during serialization.
exclude_unsetboolWhether to omit fields from the serialized output that were not explicitly set during model initialization.
exclude_defaultsboolWhether to omit fields from the serialized output if their values are equal to their defined default values.
exclude_noneboolWhether to omit fields from the serialized output that have a value of None.
exclude_computed_fieldsboolWhether to omit properties decorated as computed fields from the final serialized representation.
round_tripboolWhether to ensure serialization is performed in a way that supports full reconstruction of the original object.
serialize_unknownboolWhether to attempt serialization of object types that are not explicitly recognized by the schema.
fallbackPyAnyAn optional Python callable used to handle objects that the serializer does not know how to process.
serialize_as_anyboolWhether to serialize objects based on their runtime type rather than their declared type hint.
polymorphic_serializationboolWhether polymorphic_serialization is globally enabled / disabled for this serialization process
contextPyAnyAn 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

NameTypeDescription
pyPythonThe 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_aliasOption< bool > = nullWhether to use field aliases during serialization.
exclude_unsetbool = nullWhether to exclude fields that are not set.
exclude_defaultsbool = nullWhether to exclude fields with default values.
exclude_nonebool = nullWhether to exclude fields with None values.
exclude_computed_fieldsbool = nullWhether to exclude computed fields.
round_tripbool = nullWhether to enable round-trip serialization support.
serialize_unknownbool = nullWhether to serialize unknown fields.
fallbackOption< Bound< PyAny > > = nullAn optional fallback handler for unknown types.
serialize_as_anybool = nullWhether to serialize objects as the 'Any' type.
polymorphic_serializationOption< bool > = nullWhether polymorphic serialization is globally enabled or disabled.
contextOption< Bound< PyAny > > = nullOptional context data for the serialization process.