It's work for me:
Use toPlainOnly
property enabled and too add ClassSerializerInterceptor
like GlobalInterceptor
:
// your entity class
@Exclude({ toPlainOnly: true })
password: string;
// main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
.
.
.
app.useGlobalInterceptors(
new ClassSerializerInterceptor(app.get(Reflector))
);
}
Enable global serialization avoids the necessity to use plainToClass
individually all time...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…