Skip to content

Commit aeb42ad

Browse files
authored
Merge branch 'develop' into polymorph
2 parents 5e55a05 + 7979723 commit aeb42ad

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/TransformOperationExecutor.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,22 @@ export class TransformOperationExecutor {
210210

211211
if (!this.options.enableCircularCheck || !this.isCircular(subValue, level)) {
212212
let transformKey = this.transformationType === TransformationType.PLAIN_TO_CLASS ? newValueKey : key;
213-
let finalValue = this.transform(subSource, subValue, type, arrayType, isSubValueMap, level + 1);
214-
finalValue = this.applyCustomTransformations(finalValue, (targetType as Function), transformKey, value, this.transformationType);
213+
let finalValue;
214+
215+
if (this.transformationType === TransformationType.CLASS_TO_PLAIN) {
216+
// Get original value
217+
finalValue = value[transformKey];
218+
// Apply custom transformation
219+
finalValue = this.applyCustomTransformations(finalValue, targetType, transformKey, value, this.transformationType);
220+
// If nothing change, it means no custom transformation was applied, so use the subValue.
221+
finalValue = (value[transformKey] === finalValue) ? subValue : finalValue;
222+
// Apply the default transformation
223+
finalValue = this.transform(subSource, finalValue, type, arrayType, isSubValueMap, level + 1);
224+
} else {
225+
finalValue = this.transform(subSource, subValue, type, arrayType, isSubValueMap, level + 1);
226+
finalValue = this.applyCustomTransformations(finalValue, targetType, transformKey, value, this.transformationType);
227+
}
228+
215229
if (newValue instanceof Map) {
216230
newValue.set(newValueKey, finalValue);
217231
} else {

0 commit comments

Comments
 (0)