"""Minimum example"""
from dataclasses import dataclass
import jsons # version 1.4.1
@dataclass
class Data():
data: dict[str, str]
data = Data({'hello': 'world'})
s = jsons.dump(data)
jsons.load(s, Data) # DeserializationError
jsons.exceptions.DeserializationError: Could not deserialize value "{'hello': 'world'}" into "dict".isinstance() argument 2 cannot be a parameterized generic
I can only find two references to this exception in PEP 585 and PEP 604.
This can be resolved by creating a separate class without parameters:
...
class Data_():
data: dict
ds = jsons.load(s, Data_)
print(ds.data)
This workaround does not work for me since I have an object subclassing dict with hashed keys that require a custom deserialiser from list[int] -> range:
jsons.exceptions.DeserializationError: A detailed type is needed for cls of the form Dict[<type>, <type>] to deserialize a dict with hashed keys.
I can only find two references to this exception in PEP 585 and PEP 604.
This can be resolved by creating a separate class without parameters:
This workaround does not work for me since I have an object subclassing
dict
with hashed keys that require a custom deserialiser fromlist[int] -> range
: