From ce721317299841eeff93f37a6ab1601fc98616c1 Mon Sep 17 00:00:00 2001 From: LEE SO JUNG <90453158+xxoznge@users.noreply.github.com> Date: Wed, 12 Jun 2024 00:52:05 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9Bfix:=20=EC=9D=B4=EB=AF=B8=EC=A7=80?= =?UTF-8?q?=20=EC=97=85=EB=A1=9C=EB=93=9C=20=EC=97=90=EB=9F=AC=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../card/controller/CardController.java | 2 +- ...MultipartJackson2HttpMessageConverter.java | 35 +++++++++++++++++++ .../security/controller/UserController.java | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/ddabong/ddabongdotchiBE/domain/global/MultipartJackson2HttpMessageConverter.java diff --git a/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/controller/CardController.java b/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/controller/CardController.java index 2e3f793..cd73de3 100644 --- a/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/controller/CardController.java +++ b/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/controller/CardController.java @@ -41,7 +41,7 @@ public class CardController { @PostMapping(value = "", consumes = "multipart/form-data") public ApiResponse createCard( @UserResolver User authUser, - @RequestPart @Valid CardCreateRequest request, + @RequestPart(value = "request") @Valid CardCreateRequest request, @RequestPart(name = "cardImage") MultipartFile file ) { return ApiResponse.onSuccess(cardService.createCard(authUser, request, file)); diff --git a/src/main/java/com/ddabong/ddabongdotchiBE/domain/global/MultipartJackson2HttpMessageConverter.java b/src/main/java/com/ddabong/ddabongdotchiBE/domain/global/MultipartJackson2HttpMessageConverter.java new file mode 100644 index 0000000..d9eba8c --- /dev/null +++ b/src/main/java/com/ddabong/ddabongdotchiBE/domain/global/MultipartJackson2HttpMessageConverter.java @@ -0,0 +1,35 @@ +package com.ddabong.ddabongdotchiBE.domain.global; + +import java.lang.reflect.Type; + +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@Component +public class MultipartJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter { + + /** + * Converter for support http request with header Content-Type: multipart/form-data + */ + public MultipartJackson2HttpMessageConverter(ObjectMapper objectMapper) { + super(objectMapper, MediaType.APPLICATION_OCTET_STREAM); + } + + @Override + public boolean canWrite(Class clazz, MediaType mediaType) { + return false; + } + + @Override + public boolean canWrite(Type type, Class clazz, MediaType mediaType) { + return false; + } + + @Override + protected boolean canWrite(MediaType mediaType) { + return false; + } +} diff --git a/src/main/java/com/ddabong/ddabongdotchiBE/domain/security/controller/UserController.java b/src/main/java/com/ddabong/ddabongdotchiBE/domain/security/controller/UserController.java index 593730e..ed246ec 100644 --- a/src/main/java/com/ddabong/ddabongdotchiBE/domain/security/controller/UserController.java +++ b/src/main/java/com/ddabong/ddabongdotchiBE/domain/security/controller/UserController.java @@ -45,7 +45,7 @@ public class UserController { @PostMapping(value = "/join", consumes = "multipart/form-data") public ApiResponse join( - @Valid @RequestPart UserJoinRequest request, + @RequestPart(value = "request") @Valid UserJoinRequest request, @RequestPart(name = "profileImage") MultipartFile file ) { return ApiResponse.onSuccess(userService.join(request, file));