Deserialize class from dict from json/yaml/toml.
To have a strong-typed accessing experience like other language.
-
Build the wheel: See How to build for more info.
-
Import in your project: Install the wheel or set it as dependency in your project's package manager.
-
Use the library:
from deserializer import deserialize instance = deserialize(Class, json)
-
Prepare pdm See here for more info
-
Build Run
pdm install
to create virtual environment for you. Runpdm build
to build wheel.
-
Please make sure your class is type-hinted well. For example,
Optional[str]
orUnion[str, None]
has been deprecated by python and you need to usestr | None
instead. We do not support these deprecated styles either. -
Please make sure your class has a non-argument constructor. Most of the time this is not a problem, but you should ensure this yourself if you use a customized constructor. This means
instance = MyClass()
should be a valid way to initialize your class. For example:class MyClass: pass
This is fine, while
class MyClass: def __init__(self, argument: object): pass
This is not acceptable.