angular2-jsonapi
angular2-jsonapi copied to clipboard
Null values are not populated into model
When you json data holds attributes with null values these are not translated into the properties of the model
public transformSerializedNamesToPropertyNames<T extends JsonApiModel>(modelType: ModelType<T>, attributes: any) {
const serializedNameToPropertyName = this.getModelPropertyNames(modelType.prototype);
const properties: any = {};
Object.keys(serializedNameToPropertyName).forEach((serializedName) => {
if (attributes && attributes[serializedName] !== null && attributes[serializedName] !== undefined) {
properties[serializedNameToPropertyName[serializedName]] = attributes[serializedName];
}
});
return properties;
}
This should be:
public transformSerializedNamesToPropertyNames<T extends JsonApiModel>(modelType: ModelType<T>, attributes: any) {
if (!attributes) {
return {};
}
const serializedNameToPropertyName = this.getModelPropertyNames(modelType.prototype);
const properties: any = {};
Object.keys(serializedNameToPropertyName).forEach((serializedName) => {
if (attributes[serializedName] !== undefined) {
properties[serializedNameToPropertyName[serializedName]] = attributes[serializedName];
}
});
return properties;
}
But then you run into the issue that Date object are initiated with a wrong value instead of having the value null https://github.com/ghidoz/angular2-jsonapi/issues/242
not tested yet for other model types