Public Member Functions | |
| None | __init__ (self, SerializationType serialization_type=SerializationType.JSON) |
| Initializes a deserializer instance. | |
| IArchive | read (self, TextIO stream) |
| Reads serialized data from the specified stream and deserializes it into an archive. | |
Protected Member Functions | |
| None | _populate_archive (self, Archive archive, list|dict data) |
| Recursively populates an Archive with parsed JSON data. | |
Protected Attributes | |
| _type = serialization_type | |
Deserializer for reading serialized data and converting it into an IArchive object.
This class provides functionality to read data from a supported serialization format (currently, only JSON) and reconstruct it as an IArchive object.
Example
from ids_peak_icv.serialization import Deserializer, SerializationType
deserializer = Deserializer(SerializationType.JSON)
with open("archive.json", "r") as f:
archive = deserializer.read(f)
id = archive.get("id", int)
name = archive.get("name", str)
| None __init__ | ( | self, | |
| SerializationType | serialization_type = SerializationType.JSON ) |
Initializes a deserializer instance.
| serialization_type | The format to use for deserialization. Defaults to SerializationType.JSON. |
|
protected |
Recursively populates an Archive with parsed JSON data.
| archive | The archive to populate. |
| data | Parsed JSON data (dict, list, scalar). |
| CorruptedException | The format of the given data is invalid. |
| IArchive read | ( | self, | |
| TextIO | stream ) |
Reads serialized data from the specified stream and deserializes it into an archive.
| stream | The stream to read serialized data from. |
IArchive object containing the deserialized data.| NotSupportedException | The serialization type is not supported. |
| IOException | The parsing failed. |
| CorruptedException | The format of the given data is invalid. |
|
protected |