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
isfile
, save the content to a temporary file and return the file name.If
response_type
isdatetime.datetime
ordatetime.date
, parse the string and return thedatetime
object.If
response_type
islist
, recursively deserialize the list contents.If
response_type
isdict
, recursively deserialize the dictionary keys and values.If
response_type
is the name of an OpenAPI model, return the model object.
- Parameters:
- response
requests.Response
Response object received from the API.
- response_type
str
String name of the class represented.
- response
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)