From 269d8889d63f55b765530f0a93eab0e17af3617a Mon Sep 17 00:00:00 2001 From: Julian Paas Date: Fri, 27 Nov 2015 11:58:03 -0500 Subject: [PATCH] ignores keys that are not found in the map --- addon/serializers/json-serializer.js | 4 ++-- .../serializers/json-serializer-test.js | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/addon/serializers/json-serializer.js b/addon/serializers/json-serializer.js index 22552cf1b98..9d92c7cc9ad 100644 --- a/addon/serializers/json-serializer.js +++ b/addon/serializers/json-serializer.js @@ -716,11 +716,11 @@ export default Serializer.extend({ */ normalizeUsingDeclaredMapping: function(modelClass, hash) { var attrs = get(this, 'attrs'); - var payloadKey, normalizedKey, key; + var normalizedKey, payloadKey, key; if (attrs) { for (key in attrs) { - payloadKey = this._getMappedKey(key, modelClass); + normalizedKey = payloadKey = this._getMappedKey(key, modelClass); if (!hash.hasOwnProperty(payloadKey)) { continue; } diff --git a/tests/integration/serializers/json-serializer-test.js b/tests/integration/serializers/json-serializer-test.js index e6a4bc71895..73f61fe77dd 100644 --- a/tests/integration/serializers/json-serializer-test.js +++ b/tests/integration/serializers/json-serializer-test.js @@ -885,3 +885,24 @@ test('normalizeResponse respects `included` items (array response)', function(as { id: "3", type: "comment", attributes: { body: "comment 3" }, relationships: {} } ]); }); + +test('normalizeResponse ignores unmapped attributes', function(assert) { + env.registry.register("serializer:post", DS.JSONSerializer.extend({ + attrs: { + title: { serialize: false }, + notInMapping: { serialize: false } + } + })); + + var jsonHash = { + id: "1", + notInMapping: 'I should be ignored', + title: "Rails is omakase" + }; + + var post = env.store.serializerFor("post").normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord'); + + assert.equal(post.data.attributes.title, "Rails is omakase"); +}); + +