diff --git a/projects/angular2-jsonapi/package-lock.json b/projects/angular2-jsonapi/package-lock.json index cea8a692..5ed45f7f 100644 --- a/projects/angular2-jsonapi/package-lock.json +++ b/projects/angular2-jsonapi/package-lock.json @@ -1,6 +1,6 @@ { "name": "angular2-jsonapi", - "version": "8.2.1-beta", + "version": "8.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/projects/angular2-jsonapi/src/services/json-api-datastore.service.spec.ts b/projects/angular2-jsonapi/src/services/json-api-datastore.service.spec.ts index eb896011..74fa2d50 100644 --- a/projects/angular2-jsonapi/src/services/json-api-datastore.service.spec.ts +++ b/projects/angular2-jsonapi/src/services/json-api-datastore.service.spec.ts @@ -696,4 +696,21 @@ describe('JsonApiDatastore', () => { }); }); + + it ('should transform null values', () => { + const obj = datastore.transformSerializedNamesToPropertyNames(Author, { + name: null, + foo: 'bar', + dob: '11-11-2019', + updated_at: null, + created_at: undefined + }); + + expect(obj.name).toBe(null); + expect(obj.date_of_birth).toBe('11-11-2019'); + expect(obj.updated_at).toBe(null); + expect(obj.created_at).toBeUndefined(); + expect(obj.firstNames).toBeUndefined(); + expect(obj.foo).toBeUndefined(); + }); }); diff --git a/projects/angular2-jsonapi/src/services/json-api-datastore.service.ts b/projects/angular2-jsonapi/src/services/json-api-datastore.service.ts index 34ffe0b4..c3bf4ae5 100644 --- a/projects/angular2-jsonapi/src/services/json-api-datastore.service.ts +++ b/projects/angular2-jsonapi/src/services/json-api-datastore.service.ts @@ -219,11 +219,15 @@ export class JsonApiDatastore { } public transformSerializedNamesToPropertyNames(modelType: ModelType, attributes: any) { + if (!attributes) { + return {}; + } + const serializedNameToPropertyName = this.getModelPropertyNames(modelType.prototype); const properties: any = {}; Object.keys(serializedNameToPropertyName).forEach((serializedName) => { - if (attributes && attributes[serializedName] !== null && attributes[serializedName] !== undefined) { + if (attributes[serializedName] !== undefined) { properties[serializedNameToPropertyName[serializedName]] = attributes[serializedName]; } });