|
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( |
@@ -445,12 +444,13 @@ export class TypesAwareObjectMapper implements ITypesAwareObjectMapper { |
445 | 444 | nestedTypeInfoKey = ObjectUtil[this._conventions.remoteEntityFieldNameConvention](key); |
446 | 445 | } |
447 | 446 |
|
| 447 | + let innerSkipTypes = skipTypes |
448 | 448 | if (!skipTypes) { |
449 | | - skipTypes = key === CONSTANTS.Documents.Metadata.KEY; |
| 449 | + innerSkipTypes = key === CONSTANTS.Documents.Metadata.KEY; |
450 | 450 | } |
451 | 451 |
|
452 | 452 | const fullPath = objPathPrefix ? `${objPathPrefix}.${nestedTypeInfoKey}` : nestedTypeInfoKey; |
453 | | - result[key] = this._makeObjectLiteral(obj[key], fullPath, typeInfoCallback, knownTypes, skipTypes); |
| 453 | + result[key] = this._makeObjectLiteral(obj[key], fullPath, typeInfoCallback, knownTypes, innerSkipTypes); |
454 | 454 | return result; |
455 | 455 | }, {}); |
456 | 456 | } |
|
0 commit comments