@@ -175,7 +175,7 @@ Now you can use `users[0].getName()` and `users[0].isAdult()` methods.
175
175
}
176
176
` ` `
177
177
178
- ### Methods
178
+ ## Methods
179
179
180
180
#### plainToClass
181
181
@@ -235,7 +235,7 @@ import {deserializeArray} from "class-transformer";
235
235
let photos = deserializeArray(photos);
236
236
` ` `
237
237
238
- ### Working with nested objects
238
+ ## Working with nested objects
239
239
240
240
When you are trying to transform objects that have nested objects ,
241
241
its required to known what type of object you are trying to transform.
@@ -268,7 +268,7 @@ let album = plainToClass(Album, albumJson);
268
268
// now album is Album object with Photo objects inside
269
269
```
270
270
271
- ### Exposing getters and method return values
271
+ ## Exposing getters and method return values
272
272
273
273
You can expose what your getter or method return by setting a ` @Expose() ` decorator to those getters or methods:
274
274
@@ -294,7 +294,7 @@ export class User {
294
294
}
295
295
```
296
296
297
- ### Exposing properties with different names
297
+ ## Exposing properties with different names
298
298
299
299
If you want to expose some of properties with a different name,
300
300
you can do it by specifying a ` name ` option to ` @Expose ` decorator:
@@ -321,7 +321,7 @@ export class User {
321
321
}
322
322
```
323
323
324
- ### Skipping specific properties
324
+ ## Skipping specific properties
325
325
326
326
Sometimes you want to skip some properties during transformation.
327
327
This can be done using ` @Exclude ` decorator:
@@ -342,7 +342,7 @@ export class User {
342
342
343
343
Now when you transform a User, ` password ` property will be skipped and not be included in the transformed result.
344
344
345
- ### Skipping depend of operation
345
+ ## Skipping depend of operation
346
346
347
347
You can control on what operation you will exclude a property. Use ` toClassOnly ` or ` toPlainOnly ` options:
348
348
@@ -362,7 +362,7 @@ export class User {
362
362
363
363
Now ` password ` property will be excluded only during ` classToPlain ` operation. Oppositely, use ` toClassOnly ` option.
364
364
365
- ### Skipping all properties of the class
365
+ ## Skipping all properties of the class
366
366
367
367
You can skip all properties of the class, and expose only those are needed explicitly:
368
368
@@ -392,7 +392,7 @@ let photo = classToPlain(photo, { strategy: "excludeAll" });
392
392
393
393
In this case you don't need to ` @Exclude() ` a whole class.
394
394
395
- ### Skipping private properties, or some prefixed properties
395
+ ## Skipping private properties, or some prefixed properties
396
396
397
397
If you name your private properties with a prefix, lets say with ` _ ` ,
398
398
then you can exclude such properties from transformation too:
@@ -438,7 +438,7 @@ const plainUser = classToPlain(user, { excludePrefixes: ["_"] });
438
438
// { id: 1, name: "Johny Cage" }
439
439
```
440
440
441
- ### Using groups to control excluded properties
441
+ ## Using groups to control excluded properties
442
442
443
443
You can use groups to control what data will be exposed and what will not be:
444
444
@@ -466,7 +466,7 @@ let user1 = classToPlain(user, { groups: ["user"] }); // will contain id, name,
466
466
let user2 = classToPlain (user , { groups: [" admin" ] }); // will contain id, name and email
467
467
```
468
468
469
- ### Using versioning to control exposed and excluded properties
469
+ ## Using versioning to control exposed and excluded properties
470
470
471
471
If you are building an API that has different versions, class-transformer has extremely useful tools for that.
472
472
You can control which properties of your model should be exposed or excluded in what version. Example:
@@ -498,7 +498,7 @@ let user4 = classToPlain(user, { version: 2 }); // will contain id and name
498
498
let user5 = classToPlain (user , { version: 2.1 }); // will contain id, name nad password
499
499
```
500
500
501
- ### Сonverting date strings into Date objects
501
+ ## Сonverting date strings into Date objects
502
502
503
503
Sometimes you have a Date in your plain javascript object received in a string format.
504
504
And you want to create a real javascript Date object from it.
@@ -525,7 +525,7 @@ Note, that dates will be converted to strings when you'll try to convert class o
525
525
Same technique can be used with ` Number ` , ` String ` , ` Boolean `
526
526
primitive types when you want to convert your values into these types.
527
527
528
- ### Working with arrays
528
+ ## Working with arrays
529
529
530
530
When you are using arrays you must provide a type of the object that array contains.
531
531
This type, you specify in a ` @Type() ` decorator:
@@ -566,7 +566,7 @@ export class Photo {
566
566
567
567
Library will handle proper transformation automatically.
568
568
569
- ### Additional data transformation
569
+ ## Additional data transformation
570
570
571
571
You can perform additional data transformation using ` @Transform ` decorator.
572
572
For example, you want to make your ` Date ` object to be a ` moment ` object when you are
@@ -590,14 +590,14 @@ Now when you call `plainToClass` and send a plain representation of the Photo ob
590
590
it will convert a date value in your photo object to moment date.
591
591
` @Transform ` decorator also supports groups and versioning.
592
592
593
- ### Working with generics
593
+ ## Working with generics
594
594
595
595
Generics are not supported because TypeScript does not have good reflection abilities yet.
596
596
Once TypeScript team provide us better runtime type reelection tools, generics will be implemented.
597
597
There are some tweaks however you can use, that maybe can solve your problem.
598
598
[ Checkout this example.] ( https://github.com/pleerock/class-transformer/tree/master/sample/sample4-generics )
599
599
600
- ### How does it handle circular references?
600
+ ## How does it handle circular references?
601
601
602
602
Circular references are ignored.
603
603
For example, if you are transforming class ` User ` that contains property ` photos ` with type of ` Photo ` ,
0 commit comments