@@ -35,7 +35,6 @@ def __init__(
35
35
nullable = False ,
36
36
unordered = False ,
37
37
json_object = None ,
38
- json_object_options = None ,
39
38
):
40
39
"""
41
40
A Property is an attribute returned from the API, and defines metadata
@@ -57,8 +56,6 @@ def __init__(
57
56
NOTE: This field is currently only for annotations purposes
58
57
and does not influence any update or decoding/encoding logic.
59
58
json_object - The JSONObject class this property should be decoded into.
60
- json_object_options - The JSONObject class this property should use when
61
- serializing for PUT requests.
62
59
"""
63
60
self .mutable = mutable
64
61
self .identifier = identifier
@@ -71,7 +68,6 @@ def __init__(
71
68
self .nullable = nullable
72
69
self .unordered = unordered
73
70
self .json_class = json_object
74
- self .json_class_options = json_object_options
75
71
76
72
77
73
class MappedObject :
@@ -118,6 +114,9 @@ def _flatten_base_subclass(obj: "Base") -> Optional[Dict[str, Any]]:
118
114
119
115
@property
120
116
def dict (self ):
117
+ return self ._serialize ()
118
+
119
+ def _serialize (self , is_put : bool = False ) -> Dict [str , Any ]:
121
120
result = vars (self ).copy ()
122
121
cls = type (self )
123
122
@@ -127,7 +126,7 @@ def dict(self):
127
126
elif isinstance (v , list ):
128
127
result [k ] = [
129
128
(
130
- item .dict
129
+ item ._serialize ( is_put = is_put )
131
130
if isinstance (item , (cls , JSONObject ))
132
131
else (
133
132
self ._flatten_base_subclass (item )
@@ -140,7 +139,7 @@ def dict(self):
140
139
elif isinstance (v , Base ):
141
140
result [k ] = self ._flatten_base_subclass (v )
142
141
elif isinstance (v , JSONObject ):
143
- result [k ] = v .dict
142
+ result [k ] = v ._serialize ( is_put = is_put )
144
143
145
144
return result
146
145
@@ -282,20 +281,9 @@ def save(self, force=True) -> bool:
282
281
data [key ] = None
283
282
284
283
# Ensure we serialize any values that may not be already serialized
285
- data = _flatten_request_body_recursive (data )
284
+ data = _flatten_request_body_recursive (data , is_put = True )
286
285
else :
287
- data = self ._serialize ()
288
-
289
- for key , value in data .items ():
290
- key_property = getattr (type (self ).properties , key , None )
291
- if key_property is None :
292
- continue
293
-
294
- json_class = key_property .json_class
295
- if json_class is None :
296
- continue
297
-
298
- data [key ] = json_class .from_json (value ).dict
286
+ data = self ._serialize (is_put = True )
299
287
300
288
resp = self ._client .put (type (self ).api_endpoint , model = self , data = data )
301
289
@@ -331,7 +319,7 @@ def invalidate(self):
331
319
332
320
self ._set ("_populated" , False )
333
321
334
- def _serialize (self ):
322
+ def _serialize (self , is_put : bool = False ):
335
323
"""
336
324
A helper method to build a dict of all mutable Properties of
337
325
this object
@@ -360,7 +348,7 @@ def _serialize(self):
360
348
361
349
# Resolve the underlying IDs of results
362
350
for k , v in result .items ():
363
- result [k ] = _flatten_request_body_recursive (v )
351
+ result [k ] = _flatten_request_body_recursive (v , is_put = is_put )
364
352
365
353
return result
366
354
@@ -518,7 +506,7 @@ def make_instance(cls, id, client, parent_id=None, json=None):
518
506
return Base .make (id , client , cls , parent_id = parent_id , json = json )
519
507
520
508
521
- def _flatten_request_body_recursive (data : Any ) -> Any :
509
+ def _flatten_request_body_recursive (data : Any , is_put : bool = False ) -> Any :
522
510
"""
523
511
This is a helper recursively flatten the given data for use in an API request body.
524
512
@@ -530,15 +518,18 @@ def _flatten_request_body_recursive(data: Any) -> Any:
530
518
"""
531
519
532
520
if isinstance (data , dict ):
533
- return {k : _flatten_request_body_recursive (v ) for k , v in data .items ()}
521
+ return {
522
+ k : _flatten_request_body_recursive (v , is_put = is_put )
523
+ for k , v in data .items ()
524
+ }
534
525
535
526
if isinstance (data , list ):
536
- return [_flatten_request_body_recursive (v ) for v in data ]
527
+ return [_flatten_request_body_recursive (v , is_put = is_put ) for v in data ]
537
528
538
529
if isinstance (data , Base ):
539
530
return data .id
540
531
541
532
if isinstance (data , MappedObject ) or issubclass (type (data ), JSONObject ):
542
- return data .dict
533
+ return data ._serialize ( is_put = is_put )
543
534
544
535
return data
0 commit comments