File tree Expand file tree Collapse file tree 1 file changed +12
-14
lines changed
Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -12,22 +12,20 @@ def serialize(obj):
1212 return json .dumps (attributes_dict , indent = 2 )
1313
1414
15- def deserialize (content , klass ):
15+ def deserialize (content , klass , many = False ):
1616 json_content = json .loads (content )
17- if type (json_content ) == list :
18- for content in json :
19- pass
20- return
17+ if many :
18+ class_list = []
19+ for content in json_content :
20+ c = klass ()
21+ for key , value in content .items ():
22+ if hasattr (c , key ):
23+ setattr (c , key , value )
24+ class_list .append (c )
25+ return class_list
2126
2227 c = klass ()
2328 for key , value in json_content .items ():
24- setattr (c , key , value )
29+ if hasattr (c , key ):
30+ setattr (c , key , value )
2531 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