Files
main.tsmain
What you'll learn
- Register ClassSerializerInterceptor for the whole application and explain what instanceToPlain does to a handler's return value
- Shape a response with @Exclude, @Expose on a getter and @Transform, restricted to the way out with toPlainOnly
- Serialize plain objects by giving a route the class to treat them as, with @SerializeOptions({ type })
Press Run tests to start the app. Its log appears here.Graded endpoints
The response has no microchip, the owner is a name, and label was computed by the exposed getter
No owner property at all on the instance, so nothing is transformed and nothing is sent for it
Every instance goes through the same rules
The microchip stays behind on a single cat too
Plain objects, serialized as Cat because the route says so: microchips gone, labels present, the owner flattened on the way out only