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

@Expose() 활용하여 DTO 속성명 변경 #16

Open
develjsw opened this issue Jul 9, 2024 · 0 comments
Open

@Expose() 활용하여 DTO 속성명 변경 #16

develjsw opened this issue Jul 9, 2024 · 0 comments

Comments

@develjsw
Copy link
Owner

develjsw commented Jul 9, 2024

  1. 이슈 : 외부업체의 협업에서 API를 통해 받은 값을 내부 DB에 저장해야 하는 상황에서
    내부 컬럼 생성 규칙과 외부에서 전달받은 DTO의 속성명이 크게 차이가 나는 경우
    어떻게 편하게 해결이 가능할까 고민하게 됨

  2. 해결 방안 : DTO에서 @expose() 데코레이터를 활용하면 손 쉽게 해결 가능

import { Expose } from 'class-transformer';

export class TestDto {
     @Expose({ name: '받아온 이름' })
     내부에서 사용할 이름: 타입
}
EX)
import { Expose } from 'class-transformer';

export class TestDto {
     @Expose({ name: 'developerName' })
     peopleName: string
}
  1. 참고 사항 : @expose() 데코레이터는 속성 이름 변경 외에도
    특정 속성만 직렬화/역직렬화 하거나 특정 조건에 따라 속성을 노출시키고 싶을 때에도 사용함.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant