Skip to content

Commit

Permalink
Merge pull request aws#606 from aws/v3-json-empty-maps
Browse files Browse the repository at this point in the history
Handle empty maps in JSON serializer
  • Loading branch information
jeremeamia committed Jun 4, 2015
2 parents 4418fa6 + 06b76ff commit 0a6302b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Api/Serializer/JsonBody.php
Expand Up @@ -69,11 +69,13 @@ private function format(Shape $shape, $value)
return $value;

case 'map':
if (empty($value)) {
return new \stdClass;
}
$values = $shape->getValue();
foreach ($value as &$v) {
$v = $this->format($values, $v);
}

return $value;

case 'blob':
Expand Down
54 changes: 54 additions & 0 deletions tests/Api/test_cases/protocols/input/json.json
Expand Up @@ -297,5 +297,59 @@
}
}
]
},
{
"description": "Empty maps",
"metadata": {
"protocol": "json",
"jsonVersion": 1.1,
"targetPrefix": "com.amazonaws.foo"
},
"shapes": {
"InputShape": {
"type": "structure",
"members": {
"Map": {
"shape": "MapType"
}
}
},
"MapType": {
"type": "map",
"key": {
"shape": "StringType"
},
"value": {
"shape": "StringType"
}
},
"StringType": {
"type": "string"
}
},
"cases": [
{
"given": {
"input": {
"shape": "InputShape"
},
"name": "OperationName",
"http": {
"method": "POST"
}
},
"params": {
"Map": {}
},
"serialized": {
"body": "{\"Map\": {}}",
"headers": {
"X-Amz-Target": "com.amazonaws.foo.OperationName",
"Content-Type": "application/x-amz-json-1.1"
},
"uri": "/"
}
}
]
}
]

0 comments on commit 0a6302b

Please sign in to comment.