You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| `@TransformMethod` | `@TransformMethod({ groups: ["user"] })` | Transform the method return with classToPlain and expose the properties on the class.
597
+
598
+
The `@TransformMethod` decorator accept 2 optional arguments.
599
+
1. ClassTransformOptions - The transform options like groups, version, name
600
+
2. the method to do the transform - classToPlain or classToClass
601
+
602
+
An example:
603
+
604
+
```
605
+
@Exclude()
606
+
class User {
607
+
608
+
id: number;
609
+
610
+
@Expose()
611
+
firstName: string;
612
+
613
+
@Expose()
614
+
lastName: string;
615
+
616
+
@Expose({ groups: ['user.email'] })
617
+
email: string;
618
+
619
+
password: string;
620
+
}
621
+
622
+
class UserController {
623
+
624
+
@TransformMethod({ groups: ['user.email'] })
625
+
getUser() {
626
+
const user = new User();
627
+
user.firstName = "Snir";
628
+
user.lastName = "Segal";
629
+
user.password = "imnosuperman";
630
+
631
+
return user;
632
+
}
633
+
}
634
+
635
+
const controller = new UserController();
636
+
const user = controller.getUser();
637
+
```
638
+
639
+
the `user` variable will contain only firstName,lastName, email properties becuase they are
640
+
the exposed variables. email property is also exposed becuase we metioned the group "user.email".
641
+
593
642
## Working with generics
594
643
595
644
Generics are not supported because TypeScript does not have good reflection abilities yet.
0 commit comments