Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
response_json
)
# Locate and store the single objects.
for zenpy_object_name in self.object_mapping.class_mapping:
if zenpy_object_name in response_json:
zenpy_object = self.object_mapping.object_from_json(
zenpy_object_name,
response_json[zenpy_object_name]
)
response_objects[zenpy_object_name] = zenpy_object
# Locate and store the collections of objects.
for key, value in response_json.items():
if isinstance(value, list):
zenpy_object_name = as_singular(key)
if zenpy_object_name in self.object_mapping.class_mapping:
response_objects[key] = []
for object_json in response_json[key]:
zenpy_object = self.object_mapping.object_from_json(
zenpy_object_name,
object_json
)
response_objects[key].append(zenpy_object)
return response_objects
def _deserialize(self, key, obj, value):
if isinstance(value, dict):
key = self.format_key(key, parent=obj)
if key in self.class_mapping:
value = self.object_from_json(key, value, parent=obj)
elif as_singular(key) in self.class_mapping:
value = self.object_from_json(
as_singular(key), value, parent=obj)
elif isinstance(value, list) and self.format_key(as_singular(key), parent=obj) in self.class_mapping:
zenpy_objects = list()
for item in value:
object_type = self.format_key(as_singular(key), parent=obj)
zenpy_objects.append(self.object_from_json(
object_type, item, parent=obj))
value = zenpy_objects
return key, value
def _deserialize(self, key, obj, value):
if isinstance(value, dict):
key = self.format_key(key, parent=obj)
if key in self.class_mapping:
value = self.object_from_json(key, value, parent=obj)
elif as_singular(key) in self.class_mapping:
value = self.object_from_json(
as_singular(key), value, parent=obj)
elif isinstance(value, list) and self.format_key(as_singular(key), parent=obj) in self.class_mapping:
zenpy_objects = list()
for item in value:
object_type = self.format_key(as_singular(key), parent=obj)
zenpy_objects.append(self.object_from_json(
object_type, item, parent=obj))
value = zenpy_objects
return key, value
def _deserialize(self, key, obj, value):
if isinstance(value, dict):
key = self.format_key(key, parent=obj)
if key in self.class_mapping:
value = self.object_from_json(key, value, parent=obj)
elif as_singular(key) in self.class_mapping:
value = self.object_from_json(
as_singular(key), value, parent=obj)
elif isinstance(value, list) and self.format_key(as_singular(key), parent=obj) in self.class_mapping:
zenpy_objects = list()
for item in value:
object_type = self.format_key(as_singular(key), parent=obj)
zenpy_objects.append(self.object_from_json(
object_type, item, parent=obj))
value = zenpy_objects
return key, value
def _deserialize(self, key, obj, value):
if isinstance(value, dict):
key = self.format_key(key, parent=obj)
if key in self.class_mapping:
value = self.object_from_json(key, value, parent=obj)
elif as_singular(key) in self.class_mapping:
value = self.object_from_json(
as_singular(key), value, parent=obj)
elif isinstance(value, list) and self.format_key(as_singular(key), parent=obj) in self.class_mapping:
zenpy_objects = list()
for item in value:
object_type = self.format_key(as_singular(key), parent=obj)
zenpy_objects.append(self.object_from_json(
object_type, item, parent=obj))
value = zenpy_objects
return key, value