即使将class-transformer库中的@Exclude()装饰器添加到变量中,在创建对象时也会返回该变量。
在空构造函数和启用toPlainOnly属性的情况下,它都失败了:
@Exclude()
password: string;@Exclude({ toPlainOnly: true })
password: string;该怎么办呢?
发布于 2021-01-03 09:40:48
这是我的工作:
使用已启用的toPlainOnly属性,并像GlobalInterceptor一样添加ClassSerializerInterceptor
// 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))
);
}启用全局序列化可避免始终单独使用plainToClass ...
https://stackoverflow.com/questions/65545893
复制相似问题