diff --git a/lib/deserializer.js b/lib/deserializer.js index 1cb7c1a..a117ff3 100644 --- a/lib/deserializer.js +++ b/lib/deserializer.js @@ -21,6 +21,8 @@ module.exports = function (opts) { } function resource() { + if (!jsonapi.data) { jsonapi.data = {}; } + return new DeserializerUtils(jsonapi, jsonapi.data, opts) .perform() .then(function (result) { diff --git a/test/deserializer.js b/test/deserializer.js index bd5ae42..0baab6c 100644 --- a/test/deserializer.js +++ b/test/deserializer.js @@ -1638,4 +1638,22 @@ describe('JSON API Deserializer', function () { }); }); + + describe('when data is null', function () { + it('should return an empty object', function (done) { + var dataSet = { + data: null, + jsonapi: { + version: '1.0' + } + }; + + new JSONAPIDeserializer() + .deserialize(dataSet, function (err, json) { + expect(json).to.be.eql({}); + + done(null, json); + }); + }); + }); });