typestack / class-transformer

Decorator-based transformation, serialization, and deserialization between objects and classes.
MIT License
6.64k stars 486 forks source link

instanceToPlain not working properly using nestjs #1684

Closed AaronTrazona closed 2 months ago

AaronTrazona commented 4 months ago

Sample Class

export class Note {
    id: string
    title: string
    body: string

    @ApiProperty({ name: 'updated_at' })
    @Expose({ name: 'updated_at' })
    updatedDate: string;

    @ApiProperty({ name: 'created_at' })
    @Expose({ name: 'created_at' })
    createdDate: string;
}

    const noteTesting: Note = {
      id: 'test',
      updatedDate: '2024-02-15T17:57:43.920Z',
      createdDate: '2024-02-15T17:57:43.920Z',
      body: 'hello',
      title: 'title'
    };

    console.log('@noteTesting', instanceToPlain(noteTesting))

image The console log shows that the createdDate and updatedDate not change to created_at and updated_at

AaronTrazona commented 4 months ago

nevermind. I figure out the issue. It needs to instantiate the class.

micalevisk commented 4 months ago

@AaronTrazona so please close this issue

diffy0712 commented 2 months ago

I close this issue now as the author figured it out.

github-actions[bot] commented 1 month ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.