asphalt.serialization.object_codec

class asphalt.serialization.object_codec.DefaultCustomTypeCodec(type_key='__type__', state_key='state')

Bases: Generic[T_Serializer], CustomTypeCodec[T_Serializer]

Provides default wrappers for implementing CustomTypeCodec.

Variables:

serializer (CustomizableSerializer) – the associated serializer

Parameters:
  • type_key (str) – dict key for the type name

  • state_key (str) – dict key for the marshalled state

default_decoder(obj)

Handle a dict that might contain a wrapped state for a custom type.

Return type:

Any

unwrap_state_dict(obj)

Unwrap a marshalled state previously wrapped using wrap_state_dict().

wrap_state_dict(typename, state)

Wrap the marshalled state in a dictionary.

The returned dictionary has two keys, corresponding to the type_key and state_key options. The former holds the type name and the latter holds the marshalled state.

Parameters:
  • typename – registered name of the custom type

  • state – the marshalled state of the object

Returns:

an object serializable by the serializer