jangada.serialization.SerializableMetatype.register_primitive_type#

SerializableMetatype.register_primitive_type(primitive_type: type) None#

Register a type as a primitive that can be serialized as-is.

Primitive types are serialized without any transformation - they pass through the serialization process unchanged. Examples include str, int, float, Path, etc.

Parameters:
primitive_typetype

The type to register as primitive.

Raises:
TypeError

If attempting to register list, dict, tuple, or Serializable as primitive types (these are handled specially).

Notes

By default, the following types are registered as primitives: - str - numbers.Number (int, float, complex, etc.) - pathlib.Path

Collections (list, dict, tuple, set) are handled recursively and cannot be registered as primitives.

Examples

>>> class CustomPrimitive:
...     pass
>>> Serializable.register_primitive_type(CustomPrimitive)
>>> Serializable.is_primitive_type(CustomPrimitive)
True