Skip to content

Commit

Permalink
ignores keys that are not found in the map
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaas committed Dec 14, 2015
1 parent 845d969 commit 269d888
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addon/serializers/json-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
21 changes: 21 additions & 0 deletions tests/integration/serializers/json-serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});


0 comments on commit 269d888

Please sign in to comment.