79785428

Date: 2025-10-08 12:08:51
Score: 1.5
Natty:
Report link

Instead of going for the PipeTransform, which wasn't working properly for me, I ended up removing the @Type(() => YourClass) from the property and added a Tranform:

import { plainToInstance } from 'class-transformer';

class YourClass {
  @IsObject()
  @Transform(({ value }) =>
    plainToInstance<NestedClass, unknown>(
      NestedClass,
      typeof value === 'string' ? JSON.parse(value) : value,
    ),
  )
  @ValidateNested()
  property: NestedClass;
}
Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @Type
  • Low reputation (1):
Posted by: Joschi von Rehberg