Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
 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']