1 |
commit: 4adf87ffbc61204a90f309517351c872dc37aa44 |
2 |
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com> |
3 |
AuthorDate: Thu Aug 1 12:39:12 2013 +0000 |
4 |
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com> |
5 |
CommitDate: Thu Aug 1 12:39:12 2013 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=4adf87ff |
7 |
|
8 |
g_sorcery/serialization: Docstrings added |
9 |
|
10 |
--- |
11 |
g_sorcery/serialization.py | 14 ++++++++++++++ |
12 |
1 file changed, 14 insertions(+) |
13 |
|
14 |
diff --git a/g_sorcery/serialization.py b/g_sorcery/serialization.py |
15 |
index 28e29e5..e051596 100644 |
16 |
--- a/g_sorcery/serialization.py |
17 |
+++ b/g_sorcery/serialization.py |
18 |
@@ -16,7 +16,14 @@ import importlib |
19 |
|
20 |
|
21 |
class JSONSerializer(json.JSONEncoder): |
22 |
+ """ |
23 |
+ Custom JSON encoder. |
24 |
|
25 |
+ Each serializable class should have a method serialize |
26 |
+ that returns JSON serializable value. If class addfitionally |
27 |
+ has a classmethod deserialize that it can be deserialized |
28 |
+ and additional metainformation is added to the resulting JSON. |
29 |
+ """ |
30 |
def default(self, obj): |
31 |
if hasattr(obj, "serialize"): |
32 |
if hasattr(obj, "deserialize"): |
33 |
@@ -32,6 +39,13 @@ class JSONSerializer(json.JSONEncoder): |
34 |
|
35 |
|
36 |
def deserializeHook(json_object): |
37 |
+ """ |
38 |
+ Custom JSON decoder. |
39 |
+ |
40 |
+ Each class that can be deserialized should have classmethod deserialize |
41 |
+ that takes value (previously returned by serialize method) and transforms |
42 |
+ it into class instance. |
43 |
+ """ |
44 |
if "python_class" in json_object: |
45 |
module = importlib.import_module(json_object["python_module"]) |
46 |
cls = getattr(module, json_object["python_class"]) |