def serialize(self, data):
        """Serializes a dictionary into JSON.

        A dictionary with a single key can be passed and it can contain any
        structure.
        """
        if data is None:
            return None
        elif type(data) is dict:
            return serializer.Serializer().serialize(data)
        else:
            raise Exception(
                _("Unable to serialize object of type = '%s'") % type(data))
    def serialize(self, data):
        """Serializes a dictionary into either XML or JSON.

        A dictionary with a single key can be passed and
        it can contain any structure.
        """
        if data is None:
            return None
        elif type(data) is dict:
            return serializer.Serializer(self.get_attr_metadata()).serialize(
                data, self.content_type())
        else:
            raise Exception(
                _("Unable to serialize object of type = '%s'") % type(data))
 def deserialize(self, data, status_code):
     """Deserializes an XML or JSON string into a dictionary."""
     if status_code == 204:
         return data
     return serializer.Serializer(self.get_attr_metadata()).deserialize(
         data, self.content_type())['body']
 def deserialize(self, data, status_code):
     """Deserializes a JSON string into a dictionary."""
     if status_code == 204:
         return data
     return serializer.Serializer().deserialize(data)['body']