Skip to content

Commit 48525ea

Browse files
committed
Rename object-serializer -> object_serializer & begin deserializer implementation
1 parent 1b84b56 commit 48525ea

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

object-serializer/serializer.py

Lines changed: 0 additions & 18 deletions
This file was deleted.
File renamed without changes.

object_serializer/serializer.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import json
2+
3+
def serialize(obj):
4+
5+
''' Serializes a class object into json '''
6+
attribute_list = [attr for attr in dir(obj) if not attr.startswith('__')]
7+
attributes_dict = {}
8+
9+
for attribute in attribute_list:
10+
attributes_dict[attribute] = getattr(obj, attribute)
11+
12+
return json.dumps(attributes_dict, indent=2)
13+
14+
15+
def deserialize(content, klass):
16+
json_content = json.loads(content)
17+
if type(json_content) == list:
18+
for content in json:
19+
pass
20+
return
21+
22+
c = klass()
23+
for key, value in json_content.items():
24+
setattr(c, key, value)
25+
return c
26+
27+
28+
29+
class Pessoa:
30+
31+
def __init__(self):
32+
self.nome = 'Renato'
33+
self.idade = 23

0 commit comments

Comments
 (0)