JAVA/Spring
Spring Json 응답 시 null 값인 필드 제외하기
bestinu
2022. 2. 23. 00:28
728x90
Json으로 Response를 보낼 때, 필드가 null 값일 경우 그 필드를 제외하고 보내려면 ResponseDto에 JsonInclude 어노테이션을 사용하면 된다.
사용법은 아래와 같다.
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL) // Null 값인 필드 제외
@Builder
public class UserResponseDto {
private String email;
private String nickname;
}
728x90