arenekosreal/deserializer
Deserialize class from dict from json/yaml/toml.
deserializer
Deserialize class from dict from json/yaml/toml.
Why create this
To have a strong-typed accessing experience like other language.
How to use
-
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)
How to build
-
Prepare pdm
See here for more info -
Build
Runpdm installto create virtual environment for you.
Runpdm buildto build wheel.
Notes:
-
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 | Noneinstead.
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 meansinstance = 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.