Skip to content

Commit

Permalink
Merge pull request #511 from kyleknap/b64-rest-json
Browse files Browse the repository at this point in the history
Serialize blobs as base64 strings for rest-json
  • Loading branch information
kyleknap committed Apr 7, 2015
2 parents 53a3074 + af83126 commit 19b051f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
8 changes: 5 additions & 3 deletions botocore/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def _serialize_type_structure(self, serialized, value, shape, key):
# of the passed in serialized dict. We'll then add
# all the structure members as key/vals in the new serialized
# dictionary we just created.
new_serialized = {}
new_serialized = self.MAP_TYPE()
serialized[key] = new_serialized
serialized = new_serialized
members = shape.members
Expand Down Expand Up @@ -501,10 +501,12 @@ def _convert_header_value(self, shape, value):
return value


class RestJSONSerializer(BaseRestSerializer):
class RestJSONSerializer(BaseRestSerializer, JSONSerializer):

def _serialize_body_params(self, params, shape):
return json.dumps(params)
serialized_body = self.MAP_TYPE()
self._serialize(serialized_body, params, shape)
return json.dumps(serialized_body)


class RestXMLSerializer(BaseRestSerializer):
Expand Down
51 changes: 51 additions & 0 deletions tests/unit/protocols/input/rest-json.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,57 @@
}
]
},
{
"description": "Serialize blobs in body",
"metadata": {
"protocol": "rest-json",
"apiVersion": "2014-01-01"
},
"shapes": {
"InputShape": {
"type": "structure",
"members": {
"Foo": {
"shape": "StringType",
"location": "uri",
"locationName": "Foo"
},
"Bar": {"shape": "BlobType"}
},
"required": [
"Foo"
]
},
"StringType": {
"type": "string"
},
"BlobType": {
"type": "blob"
}
},
"cases": [
{
"given": {
"http": {
"method": "GET",
"requestUri": "/2014-01-01/{Foo}"
},
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"Foo": "foo_name",
"Bar": "Blob param"
},
"serialized": {
"body": "{\"Bar\": \"QmxvYiBwYXJhbQ==\"}",
"uri": "/2014-01-01/foo_name"
}
}
]
},
{
"description": "Omits null query params, but serializes empty strings",
"metadata": {
Expand Down

0 comments on commit 19b051f

Please sign in to comment.