diff options
author | Jauhien Piatlicki (jauhien) <piatlicki@gmail.com> | 2013-08-01 14:39:12 +0200 |
---|---|---|
committer | Jauhien Piatlicki (jauhien) <piatlicki@gmail.com> | 2013-08-01 14:39:12 +0200 |
commit | 4adf87ffbc61204a90f309517351c872dc37aa44 (patch) | |
tree | 04923305b33926f18100e0214ee0c803c368e616 /g_sorcery | |
parent | g_sorcery/g_sorcery: Docstrings added (diff) | |
download | g-sorcery-4adf87ffbc61204a90f309517351c872dc37aa44.tar.gz g-sorcery-4adf87ffbc61204a90f309517351c872dc37aa44.tar.bz2 g-sorcery-4adf87ffbc61204a90f309517351c872dc37aa44.zip |
g_sorcery/serialization: Docstrings added
Diffstat (limited to 'g_sorcery')
-rw-r--r-- | g_sorcery/serialization.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/g_sorcery/serialization.py b/g_sorcery/serialization.py index 28e29e5..e051596 100644 --- a/g_sorcery/serialization.py +++ b/g_sorcery/serialization.py @@ -16,7 +16,14 @@ import importlib class JSONSerializer(json.JSONEncoder): + """ + Custom JSON encoder. + Each serializable class should have a method serialize + that returns JSON serializable value. If class addfitionally + has a classmethod deserialize that it can be deserialized + and additional metainformation is added to the resulting JSON. + """ def default(self, obj): if hasattr(obj, "serialize"): if hasattr(obj, "deserialize"): @@ -32,6 +39,13 @@ class JSONSerializer(json.JSONEncoder): def deserializeHook(json_object): + """ + Custom JSON decoder. + + Each class that can be deserialized should have classmethod deserialize + that takes value (previously returned by serialize method) and transforms + it into class instance. + """ if "python_class" in json_object: module = importlib.import_module(json_object["python_module"]) cls = getattr(module, json_object["python_class"]) |