ParityOS Serialization¶
A simple automatic serialization library that is largely inspired by cattrs. It shares cattrs’s philosophy of being non-intrusive and not requiring subclassing or abstract method implementation. Instead it relies on automatic object structure deduction for attrs classes or dataclasses and custom (de)serialization hooks which can be registered for custom classes. This is similar to json’s default parameter to dump and object_hook parameter to load.
However with respect to cattrs it comes with some significant differences:
All objects are serialized together with a unique class tag and the serializer relies on this information for deserialization, rather than type annotations of target fields. This alleviates many troubles cattrs has with deserializing subclasses of types used as type annotations.
It inspects the object to serialize, not just its type, which allows e.g. serialization of classes themselves.
It doesn’t care about generics and typevars as all concrete type information is recorded in the serialized data. This especially allows for greater flexibility with using subclasses of generics.