Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

세션 추가 DTO 역직렬화 문제 #84

Open
gikhoon opened this issue Aug 5, 2024 · 0 comments
Open

세션 추가 DTO 역직렬화 문제 #84

gikhoon opened this issue Aug 5, 2024 · 0 comments

Comments

@gikhoon
Copy link
Member

gikhoon commented Aug 5, 2024

⚠️ 발생한 에러

세션 추가 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개이다

  1. Multipart 파일은 따로 DTO를 구성하고 다른 프로퍼티는 Json으로 선택해서 따로따로 보낼 수 있는 것
  2. 중첩된 하위 객체를 없애는 쪽으로 request DTO 구조를 바꾸는 것
  3. API를 분리해서 파일은 multipart-form으로, 중첩된 DTO는 json으로 따로 받는다.

하지만 postman에서는 1번 방식이 가능하지만 swagger를 사용하는 상황에서는 1번 방법을 사용할 수 없다.
따라서 2,3번 중에 cost가 적은 2번을 선택했다.

📡 예상 결과

🔗 참고한 자료

@gikhoon gikhoon changed the title [Fix] 세션 추가 DTO 역직렬화 문제 세션 추가 DTO 역직렬화 문제 Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant