|
1 | | -import { ObjectTypeDescriptor, ClassConstructor, ObjectLiteralDescriptor, EntityConstructor } from "../Types"; |
| 1 | +import { ObjectTypeDescriptor, ObjectLiteralDescriptor, EntityConstructor } from "../Types"; |
2 | 2 | import { throwError } from "../Exceptions"; |
3 | 3 | import { TypeUtil } from "../Utility/TypeUtil"; |
4 | 4 | import { getLogger } from "../Utility/LogUtil"; |
@@ -338,8 +338,7 @@ export class TypesAwareObjectMapper implements ITypesAwareObjectMapper { |
338 | 338 | if (!ctorOrTypeDescriptor) { |
339 | 339 | instance = Object.assign({}, rawValue); |
340 | 340 | } else if (TypeUtil.isClass(ctorOrTypeDescriptor)) { |
341 | | - instance = this._createEmptyObject(ctorOrTypeDescriptor as ClassConstructor); |
342 | | - instance = Object.assign(instance, rawValue); |
| 341 | + instance = this.createEmptyObject(ctorOrTypeDescriptor, rawValue); |
343 | 342 | } else if (TypeUtil.isObjectLiteralTypeDescriptor(ctorOrTypeDescriptor)) { |
344 | 343 | instance = (ctorOrTypeDescriptor as ObjectLiteralDescriptor).construct(rawValue); |
345 | 344 | } else { |
@@ -367,12 +366,12 @@ export class TypesAwareObjectMapper implements ITypesAwareObjectMapper { |
367 | 366 | return ctorOrTypeDescriptor; |
368 | 367 | } |
369 | 368 |
|
370 | | - private _createEmptyObject<TResult extends object>(ctor: EntityConstructor<TResult>) { |
| 369 | + protected createEmptyObject<TResult extends object>(ctor: EntityConstructor<TResult>, rawValue: object) { |
371 | 370 | if (!ctor) { |
372 | 371 | throwError("InvalidArgumentException", "ctor argument must not be null or undefined."); |
373 | 372 | } |
374 | 373 |
|
375 | | - return new ctor() as TResult; |
| 374 | + return Object.assign(new ctor(), rawValue) as TResult; |
376 | 375 | } |
377 | 376 |
|
378 | 377 | private _makeObjectLiteral( |
|
0 commit comments