openfloor.json_serializable¶
- class openfloor.json_serializable.JsonSerializable[source]¶
Bases:
ABCAbstract base class for JSON serializable objects
- classmethod from_dict(data)[source]¶
Create an instance from a dictionary or instance
When a dictionary is provided any keys that do not correspond to dataclass fields are silently preserved in
_undefined_extrasrather than being passed to the constructor. This ensures that unexpected data from external sources does not raiseTypeErrorduring construction. The preserved extras are re-emitted by__json__().- Return type:
- class openfloor.json_serializable.JsonSerializableDataclass[source]¶
Bases:
JsonSerializableBase class for JSON serializable objects that are dataclasses
- classmethod from_dict(data)[source]¶
Create an instance from a dictionary.
Extra keys in
dataare silently preserved in_undefined_extrasviasplit_kwargs(), allowing callers to pass in unfiltered JSON blobs without causing constructor failures. The preserved extras are re-emitted by__json__().- Return type:
- class openfloor.json_serializable.JsonSerializableDict(*args, **kwargs)[source]¶
Bases:
JsonSerializableBase class for JSON serializable objects that serialize to dictionaries
- class openfloor.json_serializable.JsonSerializableList(*args, **kwargs)[source]¶
Bases:
JsonSerializableBase class for JSON serializable objects that serialize to lists
- openfloor.json_serializable.split_kwargs(cls, kwargs)[source]¶
Split kwargs into defined and undefined fields for a dataclass class.
- Parameters:
cls (
Type) – The class to check fields againstkwargs (
Dict[str,Any]) – Dictionary of keyword arguments to split
- Return type:
Tuple[Dict[str,Any],Dict[str,Any]]- Returns:
Tuple of (defined_fields, undefined_fields) where each is a dictionary of the respective fields from kwargs.