JSON
hololinked.serializers.json.JSONSerializer
Bases: BaseSerializer
Serializer that wraps the msgspec JSON serialization protocol, default serializer for this package.
Source code in repo/hololinked/hololinked/serializers/json.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
Attributes
Functions
__init__
dumps
loads
default
classmethod
Method called if object is not serializable by default JSON encoder.
To override, one can subclass and implement default method and call super().default() at the very end.
Or one can directly register a type with register_type_replacement().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
the object to be serialized |
required |
Returns:
| Type | Description |
|---|---|
JSONSerializable
|
a JSON serializable representation of the object, not bytes. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if the object cannot be serialized to JSON |
Source code in repo/hololinked/hololinked/serializers/json.py
register_type_replacement
classmethod
Register custom serialization function for a particular type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
the type for which the replacement function is registered |
required | |
|
the function that takes an object of the given type and returns a JSON serializable representation of
the object. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the object_type is not a type or is the type 'type' itself |
Source code in repo/hololinked/hololinked/serializers/json.py
hololinked.serializers.json.PythonBuiltinJSONSerializer
Bases: JSONSerializer
Serializer that wraps the python builtin JSON serializer.
Source code in repo/hololinked/hololinked/serializers/json.py
Attributes
Functions
__init__
dumps
loads
dump
classmethod
load
classmethod
Load JSON from file.
Returns:
| Type | Description |
|---|---|
Any
|
the deserialized JSON object |