Valkey Dict Type Management
Type management module.
- class valkey_dict.type_management.ValkeyDictJSONDecoder(*args, **kwargs)[source]
Bases:
JSONDecoder
JSON decoder leveraging ValkeyDict existing type conversion system.
Works with ValkeyDictJSONEncoder to reconstruct Python objects from JSON using ValkeyDict decoding_registry.
Still needs work but allows for more types than without.
- __init__(*args, **kwargs)[source]
Overwrite the __init__ method from JSON decoder.
- Parameters:
*args (Any) – Positional arguments for initialization.
**kwargs (Any) – Keyword arguments for initialization.
- class valkey_dict.type_management.ValkeyDictJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]
Bases:
JSONEncoder
Extends JSON encoding capabilities by reusing ValkeyDict type conversion.
Uses existing decoding_registry to know which types to handle specially and encoding_registry (falls back to str) for converting to JSON-compatible formats.
Example
The encoded format looks like:
{ "__type__": "TypeName", "value": <encoded value> }
Notes
Uses decoding_registry (containing all supported types) to check if type needs special handling. For encoding, defaults to str() if no encoder exists in encoding_registry.
- default(o)[source]
Overwrite default from json encoder.
- Parameters:
o (Any) – Object to be serialized.
- Raises:
TypeError – If the object o cannot be serialized.
- Returns:
Serialized value.
- Return type:
Any
- valkey_dict.type_management.decode_json(s)[source]
Decode a JSON string to a Python object using the existing decoding registry.
- Parameters:
s (str) – The JSON string to be decoded.
- Returns:
The decoded Python object.
- Return type:
Any
- valkey_dict.type_management.encode_json(obj)[source]
Encode a Python object to a JSON string using the existing encoding registry.
- Parameters:
obj (Any) – The Python object to be encoded.
- Returns:
The JSON-encoded string representation of the object.
- Return type:
str