Serializers

restless.serializers

class restless.serializers.JSONSerializer
deserialize(body)

The low-level deserialization.

Underpins deserialize, deserialize_list & deserialize_detail.

Has no built-in smarts, simply loads the JSON.

Parameters

body (string) – The body of the current request

Returns

The deserialized data

Return type

list or dict

serialize(data)

The low-level serialization.

Underpins serialize, serialize_list & serialize_detail.

Has no built-in smarts, simply dumps the JSON.

Parameters

data (string) – The body for the response

Returns

A serialized version of the data

Return type

string

class restless.serializers.Serializer

A base serialization class.

Defines the protocol expected of a serializer, but only raises NotImplementedError.

Either subclass this or provide an object with the same deserialize/serialize methods on it.

deserialize(body)

Handles deserializing data coming from the user.

Should return a plain Python data type (such as a dict or list) containing the data.

Parameters

body (string) – The body of the current request

Returns

The deserialized data

Return type

list or dict

serialize(data)

Handles serializing data being sent to the user.

Should return a plain Python string containing the serialized data in the appropriate format.

Parameters

data (list or dict) – The body for the response

Returns

A serialized version of the data

Return type

string