Skip to content

Commit e8041b8

Browse files
committed
fix(serializer): fixes decoder being called on mapped properties even if
the parent object was null. Relates to #59
1 parent 05ab547 commit e8041b8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/module/serializer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
RMModule.factory('RMSerializer', ['$injector', 'inflector', '$filter', 'RMUtils', function($injector, inflector, $filter, Utils) {
44

55
function extract(_from, _path) {
6+
if(_from === null && _path.length > 1) return undefined;
7+
68
var node;
79
for(var i = 0; _from && (node = _path[i]); i++) {
810
_from = _from[node];

test/serializer-spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,16 @@ describe('Restmod serializer', function() {
252252
expect(result.brand.full_name).toEqual('Giant');
253253
});
254254

255+
it('should properly handle null parent when processing nested properties', function() {
256+
var spy = jasmine.createSpy();
257+
258+
serializer.dsl().attrMap('brand', 'brand.full_name');
259+
serializer.dsl().attrDecoder('brand', spy);
260+
261+
serializer.decode({}, null, '');
262+
expect(spy).not.toHaveBeenCalled();
263+
});
264+
255265
it('should allow mapping to a server property inside an ignored property', function() {
256266
serializer.dsl().attrMap('brandName', 'brand.full_name');
257267
serializer.dsl().attrMask('brand', true);

0 commit comments

Comments
 (0)