Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(class-transformer): plainToClass is deprectated and replaced with plainToInstance #13628

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Type } from '../type.interface';
import { ClassTransformOptions } from './class-transform-options.interface';

export interface TransformerPackage {
plainToClass<T>(
plainToInstance<T>(
cls: Type<T>,
plain: unknown,
options?: ClassTransformOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/pipes/validation.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class ValidationPipe implements PipeTransform<any> {
const isNil = value !== originalValue;
const isPrimitive = this.isPrimitive(value);
this.stripProtoKeys(value);
let entity = classTransformer.plainToClass(
let entity = classTransformer.plainToInstance(
metatype,
value,
this.transformOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/serializer/class-serializer.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class ClassSerializerInterceptor implements NestInterceptor {
if (plainOrClass instanceof options.type) {
return classTransformer.classToPlain(plainOrClass, options);
}
const instance = classTransformer.plainToClass(options.type, plainOrClass);
const instance = classTransformer.plainToInstance(options.type, plainOrClass);
return classTransformer.classToPlain(instance, options);
}

Expand Down
4 changes: 2 additions & 2 deletions sample/01-cats-app/src/common/pipes/validation.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
PipeTransform,
Type,
} from '@nestjs/common';
import { plainToClass } from 'class-transformer';
import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';

@Injectable()
Expand All @@ -15,7 +15,7 @@ export class ValidationPipe implements PipeTransform<any> {
if (!metatype || !this.toValidate(metatype)) {
return value;
}
const object = plainToClass(metatype, value);
const object = plainToInstance(metatype, value);
const errors = await validate(object);
if (errors.length > 0) {
throw new BadRequestException('Validation failed');
Expand Down
4 changes: 2 additions & 2 deletions sample/10-fastify/src/common/pipes/validation.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
PipeTransform,
Type,
} from '@nestjs/common';
import { plainToClass } from 'class-transformer';
import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';

@Injectable()
Expand All @@ -15,7 +15,7 @@ export class ValidationPipe implements PipeTransform<any> {
if (!metatype || !this.toValidate(metatype)) {
return value;
}
const object = plainToClass(metatype, value);
const object = plainToInstance(metatype, value);
const errors = await validate(object);
if (errors.length > 0) {
throw new BadRequestException('Validation failed');
Expand Down