2024-11-20 16:13:44.543 ERROR 17788 --- [nio-8080-exec-2] d.v.m.c.filter.JwtTokenFilter : Error occurs while getting header. header is null or invalid
2024-11-20 16:13:44.600 ERROR 17788 --- [nio-8080-exec-2] d.v.m.exception.GlobalControllerAdvice : Error occurs org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class dev.vinyeee.mysns.controller.request.UserLoginRequest]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `dev.vinyeee.mysns.controller.request.UserLoginRequest` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 2, column: 5]
이전엔 로그인 요청이 잘 동작했는데 jwt 관련 Filter 를 추가해주고 나니 갑자기 위의 에러가 발생했다
토큰필터에서 나는 에러는 원래 로그인 요청 시에는 토큰 발급 받기 전이라 인증헤더에 token이 들어있지 않아서
null 에러가 뜨는건 정상이라고 나오고
아래에 있는 에러에 대해서 알아보니 로그인 할 때 UserLoginRequest DTO를 @RequestBody로 받아오는데 여기서 Json 형식을 자바 객체로 바꿔주는 역직렬화가 되지 않아서 발생하는 에러라고 한다.
역직렬화 동작
- Jackson 라이브러리에서 클라이언트가 보낸 JSON 데이터를 Java 객체로 변환하는 과정
- 기본 생성자를 호출하여 객체를 생성.
- JSON 필드 값을 해당 객체의 필드에 매핑.
- 이 과정에서 기본 생성자가 없으면 Jackson이 객체를 생성할 수 없음
따라서 기본 생성자를 직접 만들어주거나
@NoArgsConstructor
를 달아주면

로그인이 잘 동작하는 것을 확인할 수 있다
'Spring🌱 > 트러블슈팅' 카테고리의 다른 글
| [spring boot] 아마존 aws micro.t2 CPU 사용량 100% 문제 해결 (0) | 2024.10.18 |
|---|---|
| [spring boot] 이미지 파일 업로드 서버 재시작 해야 보이는 오류 해결-프로젝트 외부 경로 파일 가져오기 (1) | 2024.10.18 |