Contribute to help us improve!
Are there edge cases or problems that we didn't consider? Is there a technical pitfall that we should add? Did we miss a comma in a sentence?
If you have any input for us, we would love to hear from you and appreciate every contribution. Our goal is to learn from projects for projects such that nobody has to reinvent the wheel.
Let's collect our experiences together to make room to explore the novel!
To contribute click on Contribute to this page on the toolbar.
Serializer
Serialization is the process of translating data structures or object state into a format that can be transmitted across network and reconstructed later.
NestJS by default serialize all data to JSON (JSON.stringify). Sometimes this is not enough. In some situations you need to exclude some property (e.g password). Instead doing it manually, devon4node provides an interceptor (ClassSerializerInterceptor
) that will do it for you. You only need to return a class instance as always and the interceptor will transform those class to the expected data.
The ClassSerializerInterceptor
takes the class-transformer decorators in order to know how to transform the class and then send the result to the client.
Some of class-transformer decorators are:
-
Expose
-
Exclude
-
Type
-
Transform
And methods to transform data:
-
plainToClass
-
plainToClassFromExist
-
classToPlain
-
classToClass
-
serialize
-
deserialize
-
deserializeArray
See the class-transformer page for more information.
See NestJS serialization page for more information about ClassSerializerInterceptor
.