Comments on: RequestBody and Multipart on Spring Boot https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/ Expert Digital Insights Mon, 24 Jul 2023 15:58:02 +0000 hourly 1 By: Kamel https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/#comment-129151 Mon, 24 Jul 2023 15:58:02 +0000 https://blogs.perficient.com/?p=277856#comment-129151 Hi,

I faced the same issue and solved it but adding a custom HttpMessageConverter

So if I translate for your example :

@Configuration
@EnableWebMvc
public class MyApiConfig implements WebMvcConfigurer {
@Override
public void extendMessageConverters(List<HttpMessageConverter> messageConverters) {
messageConverters.add(new UserHttpMessageConverter());
}
}

public class UserConverter extends MappingJackson2HttpMessageConverter {
@Override
public boolean canRead(Type type, Class contextClass, MediaType mediaType) {
return type.getTypeName().equals(User.class.getName());
}
}

And then in your controller you can retrieve directly the user : @RequestPart(required = true, name = “user”) User user.

It does the same thing but I find this solution more generic.

Thank you

]]>
By: Brum https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/#comment-121278 Fri, 19 May 2023 05:24:05 +0000 https://blogs.perficient.com/?p=277856#comment-121278 In Localhost works, but when I up in the server returns 415Unsupported Media Type. Somebody can help me?

]]>
By: Gautam https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/#comment-103727 Wed, 25 Jan 2023 11:36:41 +0000 https://blogs.perficient.com/?p=277856#comment-103727 can you please show how we can implement the above thing using react js.

]]>
By: Himanshu https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/#comment-96369 Wed, 14 Dec 2022 03:42:03 +0000 https://blogs.perficient.com/?p=277856#comment-96369 This was very helpful. Thanks a lot

]]>
By: Annie https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/#comment-81168 Sun, 09 Oct 2022 08:55:13 +0000 https://blogs.perficient.com/?p=277856#comment-81168 How can I read only the Json file if I get the input from UI and send the response to UI ?

]]>
By: amir choubani https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/#comment-79232 Mon, 19 Sep 2022 09:34:47 +0000 https://blogs.perficient.com/?p=277856#comment-79232 Hello.
Why you used @RequestPart(“user”) String user instead of @RequestPart(“user”) User user ?

]]>
By: Saif Khan https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/#comment-77788 Wed, 20 Jul 2022 23:46:51 +0000 https://blogs.perficient.com/?p=277856#comment-77788 Thanks man, You solved my problem

]]>
By: Rajat https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/#comment-73330 Tue, 22 Mar 2022 10:03:21 +0000 https://blogs.perficient.com/?p=277856#comment-73330 Thank you Praseela! Nothing else I tried worked, but this did!

]]>
By: Edu Costa https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/#comment-70959 Tue, 08 Mar 2022 21:33:09 +0000 https://blogs.perficient.com/?p=277856#comment-70959 Thank you very much! This is the only correct answer after many hours of research!

]]>
By: Sagar https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/#comment-33677 Sat, 16 Oct 2021 00:20:56 +0000 https://blogs.perficient.com/?p=277856#comment-33677 Can you please also write java rest client class to invoke the /upload endpoint , similar to postman ..Rather then postman we wanted to form a client request and call using RestTemplate or rest client . IT will be helpful .

]]>
By: Andre Kapp https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/#comment-32466 Tue, 05 Oct 2021 19:08:38 +0000 https://blogs.perficient.com/?p=277856#comment-32466 Awesome stuff! Never knew about this option! Been doing backends for so long, but never encountered this before.

]]>
By: Alex https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/#comment-31387 Thu, 15 Jul 2021 15:45:52 +0000 https://blogs.perficient.com/?p=277856#comment-31387 Thank’s Praseela !!

]]>