Deserialization with from_dict and from_json
Deserialization using .from_dict() and .from_json()¶
1. .from_dict()¶
.from_dict() is a class-method of "epurized" (1) class that deserialiezes dict to an object of this "epurized" class
- "epurized" class is class that was decorated by @epure()decorator
We will use Example with nested Epure values defined in to_dict() section. You can find it here:
1.1 .from_dict() when object is saved¶
Result of to_dict() with this object you can examine here:
deserialized_obj = ToDictEx.from_dict(serialized_obj)
deserialized_obj.data_id # -> "12e3d625-64bf-479b-927e-27f69cfc4872"
deserialized_obj.str_val # -> "In Tech we trust"
deserialized_obj.generic_list # -> ["cat", "dog", "yak"]
1.2 .from_dict() when object is not saved¶
Warning
Using .from_dict() with dict that was result of not saved serialized object, may lead to creation of Epure object with None or {} fields where Epure field was supposed to be
2. .from_json()¶
Similary to to_json, .from_json() is a wrapper for .from_dict() that takes json_string and additional argument of json decoder, to decode json to dict. By default, decoder is jsonpickle decoder