nlft_qsp.file
¶
Module for JSON serialization of various classes in the package.
Functions:
| Name | Description |
|---|---|
load_any |
Load any registered object dynamically based on its root |
serializable |
Class decorator to handle JSON serialization. |
load_any(file_or_path: str | Path | TextIO) -> object
¶
Load any registered object dynamically based on its root @type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_or_path
|
str | Path | TextIO
|
File path (str or Path) or an open text stream. |
required |
Returns:
| Type | Description |
|---|---|
object
|
An instantiated instance of the registered class matching |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file contains invalid JSON. |
TypeError
|
If |
Source code in nlft_qsp/file.py
serializable(type_tag: str, fields: dict)
¶
Class decorator to handle JSON serialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_tag
|
str
|
The identifier tag added/expected in JSON as |
required |
fields
|
dict
|
A mapping of { python_attribute_name: json_field_name }. |
required |