@@ -33,11 +33,13 @@ def deserialize(self, raw_data: bytes) -> Metadata:
33
33
"""Deserialize utf-8 encoded JSON bytes into Metadata object. """
34
34
try :
35
35
json_dict = json .loads (raw_data .decode ("utf-8" ))
36
- return Metadata .from_dict (json_dict )
36
+ metadata_obj = Metadata .from_dict (json_dict )
37
37
38
38
except Exception as e : # pylint: disable=broad-except
39
39
six .raise_from (DeserializationError , e )
40
40
41
+ return metadata_obj
42
+
41
43
42
44
class JSONSerializer (MetadataSerializer ):
43
45
"""A Metadata-to-JSON serialize method.
@@ -54,15 +56,17 @@ def serialize(self, metadata_obj: Metadata) -> bytes:
54
56
"""Serialize Metadata object into utf-8 encoded JSON bytes. """
55
57
try :
56
58
indent = (None if self .compact else 1 )
57
- separators = ((',' , ':' ) if self .compact else (',' , ': ' ))
58
- return json .dumps (metadata_obj .to_dict (),
59
- indent = indent ,
60
- separators = separators ,
61
- sort_keys = True ).encode ("utf-8" )
59
+ separators = ((',' , ':' ) if self .compact else (',' , ': ' ))
60
+ json_bytes = json .dumps (metadata_obj .to_dict (),
61
+ indent = indent ,
62
+ separators = separators ,
63
+ sort_keys = True ).encode ("utf-8" )
62
64
63
65
except Exception as e : # pylint: disable=broad-except
64
66
six .raise_from (SerializationError , e )
65
67
68
+ return json_bytes
69
+
66
70
67
71
class CanonicalJSONSerializer (SignedSerializer ):
68
72
"""A Signed-to-Canonical JSON 'serialize' method. """
@@ -71,7 +75,9 @@ def serialize(self, signed_obj: Signed) -> bytes:
71
75
"""Serialize Signed object into utf-8 encoded Canonical JSON bytes. """
72
76
try :
73
77
signed_dict = signed_obj .to_dict ()
74
- return encode_canonical (signed_dict ).encode ("utf-8" )
78
+ canonical_bytes = encode_canonical (signed_dict ).encode ("utf-8" )
75
79
76
80
except Exception as e : # pylint: disable=broad-except
77
81
six .raise_from (SerializationError , e )
82
+
83
+ return canonical_bytes
0 commit comments