Skip to content

Commit 7979723

Browse files
authored
Merge pull request #160 from driccio/fix-143
fix: #143 Use custom transform on CLASS_TO_PLAIN
2 parents b829396 + 3853235 commit 7979723

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
@@ -170,8 +170,22 @@ export class TransformOperationExecutor {
170170

171171
if (!this.options.enableCircularCheck || !this.isCircular(subValue, level)) {
172172
let transformKey = this.transformationType === TransformationType.PLAIN_TO_CLASS ? newValueKey : key;
173-
let finalValue = this.transform(subSource, subValue, type, arrayType, isSubValueMap, level + 1);
174-
finalValue = this.applyCustomTransformations(finalValue, targetType, transformKey, value, this.transformationType);
173+
let finalValue;
174+
175+
if (this.transformationType === TransformationType.CLASS_TO_PLAIN) {
176+
// Get original value
177+
finalValue = value[transformKey];
178+
// Apply custom transformation
179+
finalValue = this.applyCustomTransformations(finalValue, targetType, transformKey, value, this.transformationType);
180+
// If nothing change, it means no custom transformation was applied, so use the subValue.
181+
finalValue = (value[transformKey] === finalValue) ? subValue : finalValue;
182+
// Apply the default transformation
183+
finalValue = this.transform(subSource, finalValue, type, arrayType, isSubValueMap, level + 1);
184+
} else {
185+
finalValue = this.transform(subSource, subValue, type, arrayType, isSubValueMap, level + 1);
186+
finalValue = this.applyCustomTransformations(finalValue, targetType, transformKey, value, this.transformationType);
187+
}
188+
175189
if (newValue instanceof Map) {
176190
newValue.set(newValueKey, finalValue);
177191
} else {

0 commit comments

Comments
 (0)