sanitize_for_serialization#

ApiClient.sanitize_for_serialization(obj)#

Build a JSON POST object.

Based on the object type, this method returns the sanitized JSON representation to send to the server:

  • If obj is None, return None.

  • If obj is str, int, float or bool, return directly.

  • If obj is datetime.datetime or datetime.date, convert to string in iso8601 format.

  • If obj is list, sanitize each element in the list.

  • If obj is tuple, sanitize each element in the tuple.

  • If obj is dict, return the dict.

  • If obj is an OpenAPI model, return the properties dict.

Parameters:
objDeserializedType

Data to sanitize and serialize.

Examples

>>> client = ApiClient(requests.Session(),
...                    'http://my-api.com/API/v1.svc',
...                    SessionConfiguration())
... client.sanitize_for_serialization({'key': 'value'})
{'key': 'value'}
>>> client = ApiClient(requests.Session(),
...                    'http://my-api.com/API/v1.svc',
...                    SessionConfiguration())
... client.sanitize_for_serialization(datetime.datetime(2015, 10, 21, 10, 5, 10))
'2015-10-21T10:05:10'