deserialize#

ApiClient.deserialize(response, response_type)#

Deserialize the response into an object.

Based on the type of response, the appropriate object is created for use.

For responses that are in JSON format, this method processes the response and returns it:

  • If response_type is file, save the content to a temporary file and return the file name.

  • If response_type is datetime.datetime or datetime.date, parse the string and return the datetime object.

  • If response_type is list, recursively deserialize the list contents.

  • If response_type is dict, recursively deserialize the dictionary keys and values.

  • If response_type is the name of an OpenAPI model, return the model object.

Parameters:
responserequests.Response

Response object received from the API.

response_typestr

String name of the class represented.

Examples

>>> client = ApiClient(requests.Session(),
...                    'http://my-api.com/API/v1.svc',
...                    SessionConfiguration())
... api_response = requests.Response()
... api_response._content = b"{'key': 'value'}"
... client.deserialize(api_response, 'Dict[str, str]]')
{'key': 'value'}
>>> client = ApiClient(requests.Session(),
...                    'http://my-api.com/API/v1.svc',
...                    SessionConfiguration())
... api_response = requests.Response()
... api_response._content = b"'2015-10-21T10:05:10'"
... client.deserialize(api_response, 'datetime.datetime')
datetime.datetime(2015, 10, 21, 10, 5, 10)