Skip to content

Commit 48a6ef2

Browse files
author
Umed Khudoiberdiev
authored
Merge pull request #33 from artemln/master
Fix transform
2 parents 201e621 + f7bc93e commit 48a6ef2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/TransformOperationExecutor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ export class TransformOperationExecutor {
158158
}
159159

160160
if (!this.isCircular(subValue, level)) {
161+
let transformKey = this.transformationType === "plainToClass" ? newValueKey : key;
161162
let finalValue = this.transform(subSource, subValue, type, arrayType, isSubValueMap, level + 1);
162-
finalValue = this.applyCustomTransformations(finalValue, targetType, key);
163+
finalValue = this.applyCustomTransformations(finalValue, targetType, transformKey);
163164
if (newValue instanceof Map) {
164165
newValue.set(newValueKey, finalValue);
165166
} else {

test/functional/custom-transform.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ import * as moment from "moment";
66

77
describe("custom transformation decorator", () => {
88

9+
it("@Expose decorator with \"name\" option should work with @Transform decorator", () => {
10+
defaultMetadataStorage.clear();
11+
12+
class User {
13+
14+
@Expose({name: "user_name"})
15+
@Transform(value => value.toUpperCase())
16+
name: string;
17+
}
18+
19+
let plainUser = {
20+
user_name: "Johny Cage"
21+
};
22+
23+
const classedUser = plainToClass(User, plainUser);
24+
classedUser.name.should.be.equal("JOHNY CAGE");
25+
});
26+
927
it("@Transform decorator logic should be executed depend of toPlainOnly and toClassOnly set", () => {
1028
defaultMetadataStorage.clear();
1129

0 commit comments

Comments
 (0)