Move multipart support to dedicated converter

Prior to this commit, gh-36255 introduced the new
`MultipartHttpMessageConverter`, focusing on multipart message
conversion in a separate converter. The `FormHttpMessageConverter` did
conflate URL encoded forms and multipart messages in the same converter.

With the introduction of the new converter and related types in the same
package (with `Part`, `FormFieldPart` and `FilePart`), we can now
revisit this arrangement.

This commit restricts the `FormHttpMessageConverter` to URL encoded
forms only and as a result, changes its implementation to only consider
`MultiValueMap<String, String>` types for reading and writing HTTP
messages. Because type erasure, this converter is now a
`SmartHttpMessageConverter` to get better type information with
`ResolvableType`.

As a result, the `AllEncompassingFormHttpMessageConverter` is formally
deprecated and replaced by the `MultipartHttpMessageConverter`, by
setting part converters explicitly in its constructor.

Closes gh-36256
This commit is contained in:
Brian Clozel
2026-03-26 15:08:58 +01:00
parent 44302aca93
commit abc3cfc7be
22 changed files with 250 additions and 949 deletions
@@ -25,9 +25,10 @@ import org.junit.jupiter.api.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.multipart.MultipartHttpMessageConverter;
import org.springframework.mock.http.client.MockClientHttpRequest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.util.LinkedMultiValueMap;
@@ -55,6 +56,7 @@ class MultipartRequestMatchersTests {
@BeforeEach
void setup() {
this.request.setMethod(HttpMethod.POST);
this.request.getHeaders().setContentType(MediaType.MULTIPART_FORM_DATA);
}
@@ -188,7 +190,7 @@ class MultipartRequestMatchersTests {
}
private void writeForm() throws IOException {
new FormHttpMessageConverter().write(this.input, MediaType.MULTIPART_FORM_DATA,
new MultipartHttpMessageConverter().write(this.input, MediaType.MULTIPART_FORM_DATA,
new HttpOutputMessage() {
@Override
public OutputStream getBody() throws IOException {