-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
MongoDB를 사용 중이라면,
@Document
data class MyCollection(
@id
val id: String? = null,
val name: String,
val content: String
)요런 식으로 Document 클래스를 정의할테고,
API 응답 바디로 대게는 다른 DTO를 만들어 사용할테지만,
간단하게 하느라 요 Document 클래스를 그대로 사용해야 한다면?
id 값은 보통 클라이언트에 노출하지 않기 때문에 요 필드만 제외하고 응답을 반환하고 싶다.
이럴 때는 새로 DTO를 정의할 필요 없이, 제외하고 싶은 필드에 @JsonIgnore만 추가하면 직렬화 시에 제외된다.
예제)
@Document
data class MyCollection(
@id
@JsonIgnore
val id: String? = null,
val name: String,
val content: String
)응답 예시
{
"name" : "testName",
"content" : "testContent"
}Reactions are currently unavailable