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):
12
12
return json .dumps (attributes_dict , indent = 2 )
13
13
14
14
15
- def deserialize (content , klass ):
15
+ def deserialize (content , klass , many = False ):
16
16
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
21
26
22
27
c = klass ()
23
28
for key , value in json_content .items ():
24
- setattr (c , key , value )
29
+ if hasattr (c , key ):
30
+ setattr (c , key , value )
25
31
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