Skip to content

Commit

Permalink
reduce one call to the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
badetitou committed Aug 23, 2023
1 parent 1c776cf commit 83e7b89
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/core/JsonParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,9 @@ export class JsonParser<T> {
const remainingKeys = classKeys.filter(k => Object.hasOwnProperty.call(obj, k) && !keysToBeExcluded.has(k));
let unknownKeys = [];

const hasJsonAnySetter =
this.cachedHasMetadata('JsonAnySetter', currentMainCreator, null, context);
const jsonAnySetter: JsonAnySetterOptions =
this.cachedGetMetadata('JsonAnySetter', instance.constructor, null, context);
const hasJsonAnySetter = jsonAnySetter != null;
const jsonIgnoreProperties: JsonIgnorePropertiesOptions =
this.cachedGetMetadata('JsonIgnoreProperties', currentMainCreator, null, context);
// add remaining properties and ignore the ones that are not part of "instance"
Expand All @@ -870,7 +871,8 @@ export class JsonParser<T> {
instance[key] = this.parseJsonClassType(context, globalContext, obj, key, parent);
} else if (hasJsonAnySetter && Object.hasOwnProperty.call(obj, key)) {
// for any other unrecognized properties found
this.parseJsonAnySetter(instance, obj, key, context);
// this.parseJsonAnySetter(instance, obj, key, context);
this.applyParseJsonAnySetter(jsonAnySetter, instance, obj, key);
} else if (!classHasOwnProperty(currentMainCreator, key, null, context) &&
( (jsonIgnoreProperties == null && context.features.deserialization.FAIL_ON_UNKNOWN_PROPERTIES) ||
(jsonIgnoreProperties != null && !jsonIgnoreProperties.ignoreUnknown)) ) {
Expand Down Expand Up @@ -1418,9 +1420,7 @@ export class JsonParser<T> {
* @param key
* @param context
*/
private parseJsonAnySetter(replacement: any, obj: any, key: string, context: JsonParserTransformerContext): void {
const jsonAnySetter: JsonAnySetterOptions =
this.cachedGetMetadata('JsonAnySetter', replacement.constructor, null, context);
private applyParseJsonAnySetter(jsonAnySetter: JsonAnySetterOptions , replacement: any, obj: any, key: string): void {
if (jsonAnySetter && replacement[jsonAnySetter._propertyKey]) {
if (typeof replacement[jsonAnySetter._propertyKey] === 'function') {
replacement[jsonAnySetter._propertyKey](key, obj[key]);
Expand Down

0 comments on commit 83e7b89

Please sign in to comment.