File tree Expand file tree Collapse file tree 3 files changed +33
-18
lines changed
Expand file tree Collapse file tree 3 files changed +33
-18
lines changed Load Diff This file was deleted.
File renamed without changes.
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments