tlc.core.serializable_object¶

Base class adding schema, type identity, serialization versioning, and JSON serialization to BaseObject.

Module Contents¶

Classes¶

Class

Description

SerializableObject

Adds schema, type identity, serialization versioning, and JSON serialization to BaseObject.

API¶

class SerializableObject(
*,
init_parameters: Any = None,
)¶

Bases: tlc.core.base_object.BaseObject

Adds schema, type identity, serialization versioning, and JSON serialization to BaseObject.

This level carries no URL and no persistence logic.

Parameters:

init_parameters – A dictionary containing the initial values of the object’s properties.

ensure_complete_schema() None¶

Make sure the schema is populated with all properties.

ensure_dependent_properties() None¶

Make sure dependent properties are populated.

Override in subclasses to ensure the required dependent properties are populated.

ensure_fully_defined() None¶

Make sure the internal state of the object is fully defined.

For most objects, this simply amounts to populating the schema property according to the properties which are directly present within the class.

AddressableObject overrides this with a @final version that adds write-back logic.

ensure_minimal_schema() None¶

Make sure the schema is populated with the minimal properties.

classmethod from_dict(
d: dict[str, Any],
) SerializableObject¶

Create a SerializableObject from a dictionary containing a type field and init parameters.

This performs a type-registry lookup and calls the constructor with the dictionary as init_parameters. Use this to reconstruct inline (non-URL) objects from their serialized form.

.. note::

If the resolved type is an AddressableObject subclass, calling this method will trigger URL generation and object-registry side effects. Prefer from_url() for URL-backed objects.

Parameters:

d – A dictionary with at least a type key mapping to a registered type name.

Returns:

A fully initialized instance of the registered type.

Raises:
  • KeyError – If d does not contain a type key.

  • ValueError – If the type value is not a registered type name.

should_include_schema_in_json(
_schema: Schema,
) bool¶

Indicate whether the schema property of this object should be included when serializing to JSON.

Parameters:

_schema – The schema of the object. This is passed in to allow subclasses to make decisions based on the schema of the object, but it is not used in the base implementation.

to_json(
init_level: int = 1,
) str¶

Return a JSON representation of this object.

This will be sufficient to recreate a fully functioning clone of the object at a later time.

Note that for brevity, properties with default values are not written to the string.

Parameters:

init_level – The level of initialization to use when serializing the object. 1: Minimal schema 2: Complete schema 3: Fully defined object

Returns:

A JSON representation of this object.