File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 1
1
# Table of contents
2
2
3
3
- [ Getting Started] ( pages/01-getting-started.md )
4
+ - [ Basic usage] ( pages/02-basis-usage.md )
Original file line number Diff line number Diff line change
1
+ # Basic usage
2
+
3
+ There are two main exported functions what can be used for transformations:
4
+
5
+ - ` plainToClass ` - transforms a plain object to an instance of the specified class constructor
6
+ - ` classToPlain ` - transforms a _ known_ class instance to a plain object
7
+
8
+ Both function transforms the source object to the target via applying the metadata registered by the decorators on
9
+ the class definition. The four main decorators are:
10
+
11
+ - ` @Expose ` specifies how expose the given property on the plain object
12
+ - ` @Exclude ` marks the property as skipped, so it won't show up in the transformation
13
+ - ` @Transform ` allows specifying a custom transformation on the property via a custom handler
14
+ - ` @Type ` decorator explicitly sets the type of the property, during the transformation ` class-transformer ` will attempt
15
+ to create an instance of the specified type
16
+
17
+ You must always decorate all your properties with an ` @Expose ` or ` @Exclude ` decorator.
18
+
19
+ > ** NOTE:** It's important to remember ` class-transformer ` will call the target type with am empty constructor, so if
20
+ > you are using a type what requires special setup, you need to use a ` @Transform ` decorator and create the instance yourself.
You can’t perform that action at this time.
0 commit comments