diff --git a/.changes/next-release/bugfix-DocumentClient-318ee4e7.json b/.changes/next-release/bugfix-DocumentClient-318ee4e7.json new file mode 100644 index 0000000000..2edd0abe37 --- /dev/null +++ b/.changes/next-release/bugfix-DocumentClient-318ee4e7.json @@ -0,0 +1,5 @@ +{ + "type": "bugfix", + "category": "DocumentClient", + "description": "Fixes issue stringifying sets by only including values." +} \ No newline at end of file diff --git a/lib/dynamodb/set.js b/lib/dynamodb/set.js index 8a768d8a07..e544c2e913 100644 --- a/lib/dynamodb/set.js +++ b/lib/dynamodb/set.js @@ -53,6 +53,14 @@ var DynamoDBSet = util.inherit({ }); } } + }, + + /** + * Render the underlying values only when converting to JSON. + */ + toJSON: function() { + var self = this; + return self.values; } }); diff --git a/test/dynamodb/document_client.spec.js b/test/dynamodb/document_client.spec.js index 2130682860..d4838100fb 100644 --- a/test/dynamodb/document_client.spec.js +++ b/test/dynamodb/document_client.spec.js @@ -4,6 +4,7 @@ var AWS = helpers.AWS; var Buffer = AWS.util.Buffer; var encode = AWS.util.base64.encode; + var isBrowser = AWS.util.isBrowser; var docClient = null; var NumberValue = require('../../lib/dynamodb/numberValue'); @@ -1272,6 +1273,75 @@ }); }); + it('stringifies string sets', function(done) { + var outputString, wire; + wire = JSON.stringify({ + Item: { + foo: { + 'SS': ['bar', 'baz', 'quux'] + } + } + }); + outputString = '{"Item":{"foo":["bar","baz","quux"]}}'; + helpers.mockHttpResponse(200, {}, wire); + docClient.get({ + Key: { + foo: 1 + } + }, function(err, data) { + expect(JSON.stringify(data)).to.eql(outputString); + done(); + }); + }); + + it('stringifies number sets', function(done) { + var outputString, wire; + wire = JSON.stringify({ + Item: { + foo: { + 'NS': ['1', '2', '3'] + } + } + }); + outputString = '{"Item":{"foo":[1,2,3]}}'; + helpers.mockHttpResponse(200, {}, wire); + docClient.get({ + Key: { + foo: 1 + } + }, function(err, data) { + expect(JSON.stringify(data)).to.eql(outputString); + done(); + }); + }); + + it('stringifies binary sets', function(done) { + var bar, baz, outputString, quux, wire; + bar = new Buffer('bar'); + baz = new Buffer('baz'); + quux = new Buffer('quux'); + wire = JSON.stringify({ + Item: { + foo: { + 'BS': [encode(bar), encode(baz), encode(quux)] + } + } + }); + outputString = '{"Item":{"foo":[{"type":"Buffer","data":[98,97,114]},{"type":"Buffer","data":[98,97,122]},{"type":"Buffer","data":[113,117,117,120]}]}}'; + if (process.version < 'v0.12' && !isBrowser()) { + outputString = '{"Item":{"foo":[[98,97,114],[98,97,122],[113,117,117,120]]}}'; + } + helpers.mockHttpResponse(200, {}, wire); + docClient.get({ + Key: { + foo: 1 + } + }, function(err, data) { + expect(JSON.stringify(data)).to.eql(outputString); + done(); + }); + }); + it('translates recursive maps', function(done) { var output, wire; wire = JSON.stringify({