Deserializer Class

Response object model deserializer.

Inheritance
builtins.object
Deserializer

Constructor

Deserializer(classes=None)

Parameters

classes
dict
default value: None

Class type dictionary for deserializing complex types.

Variables

key_extractors
list

Ordered list of extractors to be used by this deserializer.

Methods

deserialize_base64

Deserialize base64 encoded string into string.

deserialize_basic

Deserialize basic builtin data type from string. Will attempt to convert to str, int, float and bool. This function will also accept '1', '0', 'true' and 'false' as valid bool values.

deserialize_bytearray

Deserialize string into bytearray.

deserialize_data

Process data for deserialization according to data type.

deserialize_date

Deserialize ISO-8601 formatted string into Date object.

deserialize_decimal

Deserialize string into Decimal object.

deserialize_dict

Deserialize a dictionary.

deserialize_duration

Deserialize ISO-8601 formatted string into TimeDelta object.

deserialize_enum

Deserialize string into enum object.

If the string is not a valid enum value it will be returned as-is and a warning will be logged.

deserialize_iso

Deserialize ISO-8601 formatted string into Datetime object.

deserialize_iter

Deserialize an iterable.

deserialize_long

Deserialize string into long (Py2) or int (Py3).

deserialize_object

Deserialize a generic object. This will be handled as a dictionary.

deserialize_rfc

Deserialize RFC-1123 formatted string into Datetime object.

deserialize_time

Deserialize ISO-8601 formatted string into time object.

deserialize_unicode

Preserve unicode objects in Python 2, otherwise return data as a string.

deserialize_unix

Serialize Datetime object into IntTime format. This is represented as seconds.

failsafe_deserialize

Ignores any errors encountered in deserialization, and falls back to not deserializing the object. Recommended for use in error deserialization, as we want to return the HttpResponseError to users, and not have them deal with a deserialization error.

deserialize_base64

Deserialize base64 encoded string into string.

static deserialize_base64(attr)

Parameters

attr
str
Required

response string to be deserialized.

Return type

Exceptions

TypeError if string format invalid.

deserialize_basic

Deserialize basic builtin data type from string. Will attempt to convert to str, int, float and bool. This function will also accept '1', '0', 'true' and 'false' as valid bool values.

deserialize_basic(attr, data_type)

Parameters

attr
str
Required

response string to be deserialized.

data_type
str
Required

deserialization data type.

Return type

Exceptions

TypeError if string format is not valid.

deserialize_bytearray

Deserialize string into bytearray.

static deserialize_bytearray(attr)

Parameters

attr
str
Required

response string to be deserialized.

Return type

Exceptions

TypeError if string format invalid.

deserialize_data

Process data for deserialization according to data type.

deserialize_data(data, data_type)

Parameters

data
str
Required

The response string to be deserialized.

data_type
str
Required

The type to deserialize to.

Returns

Deserialized object.

Exceptions

DeserializationError if deserialization fails.

deserialize_date

Deserialize ISO-8601 formatted string into Date object.

static deserialize_date(attr)

Parameters

attr
str
Required

response string to be deserialized.

Return type

<xref:Date>

Exceptions

DeserializationError if string format invalid.

deserialize_decimal

Deserialize string into Decimal object.

static deserialize_decimal(attr)

Parameters

attr
str
Required

response string to be deserialized.

Return type

<xref:Decimal>

Exceptions

DeserializationError if string format invalid.

deserialize_dict

Deserialize a dictionary.

deserialize_dict(attr, dict_type)

Parameters

attr
<xref:<xref:dict/list>>
Required

Dictionary to be deserialized. Also accepts a list of key, value pairs.

dict_type
str
Required

The object type of the items in the dictionary.

Return type

Exceptions

TypeError if string format invalid.

deserialize_duration

Deserialize ISO-8601 formatted string into TimeDelta object.

static deserialize_duration(attr)

Parameters

attr
str
Required

response string to be deserialized.

Return type

<xref:TimeDelta>

Exceptions

DeserializationError if string format invalid.

deserialize_enum

Deserialize string into enum object.

If the string is not a valid enum value it will be returned as-is and a warning will be logged.

static deserialize_enum(data, enum_obj)

Parameters

data
str
Required

Response string to be deserialized. If this value is None or invalid it will be returned as-is.

enum_obj
<xref:Enum>
Required

Enum object to deserialize to.

Return type

<xref:Enum>

Exceptions

TypeError if string format invalid.

deserialize_iso

Deserialize ISO-8601 formatted string into Datetime object.

static deserialize_iso(attr)

Parameters

attr
str
Required

response string to be deserialized.

Return type

<xref:Datetime>

Exceptions

DeserializationError if string format invalid.

deserialize_iter

Deserialize an iterable.

deserialize_iter(attr, iter_type)

Parameters

attr
list
Required

Iterable to be deserialized.

iter_type
str
Required

The type of object in the iterable.

Return type

Exceptions

TypeError if string format invalid.

deserialize_long

Deserialize string into long (Py2) or int (Py3).

static deserialize_long(attr)

Parameters

attr
str
Required

response string to be deserialized.

Return type

<xref:long>,
int

Exceptions

ValueError if string format invalid.

deserialize_object

Deserialize a generic object. This will be handled as a dictionary.

deserialize_object(attr, **kwargs)

Parameters

attr
dict
Required

Dictionary to be deserialized.

Return type

Exceptions

TypeError if non-builtin datatype encountered.

deserialize_rfc

Deserialize RFC-1123 formatted string into Datetime object.

static deserialize_rfc(attr)

Parameters

attr
str
Required

response string to be deserialized.

Return type

<xref:Datetime>

Exceptions

DeserializationError if string format invalid.

deserialize_time

Deserialize ISO-8601 formatted string into time object.

static deserialize_time(attr)

Parameters

attr
str
Required

response string to be deserialized.

Return type

Exceptions

DeserializationError if string format invalid.

deserialize_unicode

Preserve unicode objects in Python 2, otherwise return data as a string.

static deserialize_unicode(data)

Parameters

data
str
Required

response string to be deserialized.

Return type

str,
<xref:unicode>

Exceptions

TypeError if string format invalid.

deserialize_unix

Serialize Datetime object into IntTime format. This is represented as seconds.

static deserialize_unix(attr)

Parameters

attr
int
Required

Object to be serialized.

Return type

<xref:Datetime>

Exceptions

DeserializationError if format invalid

failsafe_deserialize

Ignores any errors encountered in deserialization, and falls back to not deserializing the object. Recommended for use in error deserialization, as we want to return the HttpResponseError to users, and not have them deal with a deserialization error.

failsafe_deserialize(target_obj, data, content_type=None)

Parameters

target_obj
str
Required

The target object type to deserialize to.

data
<xref:<xref:str/dict>>
Required

The response data to deseralize.

content_type
str
default value: None

Swagger "produces" if available.

Exceptions

TypeError if string format invalid.

Attributes

basic_types

basic_types = {<class 'str'>: 'str', <class 'int'>: 'int', <class 'bool'>: 'bool', <class 'float'>: 'float'}

valid_date

valid_date = re.compile('\\d{4}[-]\\d{2}[-]\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.?\\d*Z?[-+]?[\\d{2}]?:?[\\d{2}]?')