You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When : multipart/form 데이터 안에 중첩 DTO가 있을 때 Then : 역직렬화가 되지 않아 DTO로 만들어지지 않는 문제 발생
해당 문제는 MultipartFile와 DTO를 한 번에 받을 수 있는 요청를 보낼 때 중첩된 DTO 형태가 있을 때 발생한다.
예를 들면 record request( LocalDate sessionDate, AttendanceDeadLineDto attendanceDeadLine)
처럼 request DTO 안에 AttendanceDeadLineDto 가 있을 때 AttendanceDeadLineDto 로 인식하지 못하고 String으로 보내버리는 문제다.
따라서 String을 Object로 convert 할 수 없어 에러가 발생한다. cannot convert value of type 'java.lang.string' to required type dto
✅ 수정한 내용
해결할 수 있는 방식은 총 2개이다
Multipart 파일은 따로 DTO를 구성하고 다른 프로퍼티는 Json으로 선택해서 따로따로 보낼 수 있는 것
중첩된 하위 객체를 없애는 쪽으로 request DTO 구조를 바꾸는 것
API를 분리해서 파일은 multipart-form으로, 중첩된 DTO는 json으로 따로 받는다.
하지만 postman에서는 1번 방식이 가능하지만 swagger를 사용하는 상황에서는 1번 방법을 사용할 수 없다.
따라서 2,3번 중에 cost가 적은 2번을 선택했다.
📡 예상 결과
🔗 참고한 자료
The text was updated successfully, but these errors were encountered:
세션 추가 DTO 역직렬화 문제 해결
에러가 발생한 상황
When : multipart/form 데이터 안에 중첩 DTO가 있을 때
Then : 역직렬화가 되지 않아 DTO로 만들어지지 않는 문제 발생
해당 문제는 MultipartFile와 DTO를 한 번에 받을 수 있는 요청를 보낼 때 중첩된 DTO 형태가 있을 때 발생한다.
예를 들면
record request( LocalDate sessionDate, AttendanceDeadLineDto attendanceDeadLine)
처럼 request DTO 안에
AttendanceDeadLineDto
가 있을 때AttendanceDeadLineDto
로 인식하지 못하고 String으로 보내버리는 문제다.따라서 String을 Object로 convert 할 수 없어 에러가 발생한다.
cannot convert value of type 'java.lang.string' to required type dto
✅ 수정한 내용
해결할 수 있는 방식은 총 2개이다
하지만 postman에서는 1번 방식이 가능하지만 swagger를 사용하는 상황에서는 1번 방법을 사용할 수 없다.
따라서 2,3번 중에 cost가 적은 2번을 선택했다.
📡 예상 결과
🔗 참고한 자료
The text was updated successfully, but these errors were encountered: