개발일지/2023_한이음
[개발]🚨ERROR - .w.s.m.s.DefaultHandlerExceptionResolver
기억지기 개발자
2023. 6. 23. 21:39
🛤️현상
2023-06-21 17:09:46.561 WARN 11180 --- [nio-8080-exec-7] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of
hanium.highwayspring.school.School
(although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (1); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of
hanium.highwayspring.school.School
(although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (1) at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 10, column: 16] (through reference chain: hanium.highwayspring.review.ReviewDTO["schoolId"])]
🌸과정
hanium.highwayspring.school.School 클래스에서 int/Int-argument 생성자 또는 팩토리 메서드가 없어서 해당 오류가 발생했고.
또한, ReviewDTO 클래스에서 schoolId 필드의 값이 Number 타입으로 제공되었는데
해당 값을 역직렬화할 수 있는 int/Int-argument 생성자 또는 팩토리 메서드도 없어서 오류가 발생했습니다.
들어오는 값은 Long 자료형인데, review 엔티티에 있는 schoolId 필드는 School 타입이라 오류가 발생한 거 같아
School 클래스에서 int/Int-argument 생성자 생성해 보기로 했다.