com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
No serializer found for class com.nts.domain.user.dto.UserCreateResponse
and no properties discovered to create BeanSerializer
(to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
(through reference chain: com.nts.domain.Response["result"])
๊ฐ๋จํ Post ์ปจํธ๋กค๋ฌ API๋ฅผ ๋ง๋ค๊ณ , ํ ์คํธ๋ฅผ ํด๋ดค๋๋ฐ ์์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
ํด์ํด๋ณด๋ฉด, jackson ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํด์ ๊ฐ์ฒด๋ฅผ JSON ํ์์ผ๋ก ์๋ตํ๊ธฐ ์ํด ์ง๋ ฌํ ํ๋ ๊ณผ์ ์์ ์๋ฌ๊ฐ ๋ฐ์ํ ๊ฒ ๊ฐ๋ค.
@Builder
public class UserCreateResponse {
private Long userId;
private String name;
public static UserCreateResponse from(User user) {
return UserCreateResponse.builder()
.userId(user.getId())
.name(user.getName())
.build();
}
}
๋ด๊ฐ ์๋ตํ๋ ค๊ณ ํ๋ ๊ฐ์ฒด๋ ์์ ๊ฐ์๊ณ , ์ ๊ฐ์ฒด๋ฅผ ์ง๋ ฌํ ํ๋๋ฐ ์คํจํ๋ค๋ ๊ฒ์ด๋ค.
์ด์ ๋, ์ ๊ฐ์ฒด๋ private ํ๋๋ฅผ ๊ฐ๊ณ ์์๊ณ ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ ๊ทผํ ์ ์์๋ ๊ฒ์ด๋ค.
๋ฐ๋ผ์, lombok ์ด๋
ธํ
์ด์
์ธ @Getter
๋ฅผ ๋ถ์ฌ ์ธ๋ถ์์ ์ ๊ทผ ๊ฐ๋ฅํ๋๋ก ํด์ฃผ๋ฉด ํด๊ฒฐ๋๋ค.