即使将类转换@Exclude()器库中的装饰器添加到变量中,它也会在创建对象时返回。
使用空构造函数和toPlainOnly启用属性都失败:
@Exclude()
password: string;
@Exclude({ toPlainOnly: true })
password: string;
该怎么办?
即使将类转换@Exclude()器库中的装饰器添加到变量中,它也会在创建对象时返回。
使用空构造函数和toPlainOnly启用属性都失败:
@Exclude()
password: string;
@Exclude({ toPlainOnly: true })
password: string;
该怎么办?
这对我有用:
使用toPlainOnly已启用的属性并添加ClassSerializerInterceptor如下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))
);
}
启用全局序列化避免了一直plainToClass单独使用的必要性......