diff --git a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java index a34a039894..35ee06d4db 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java @@ -147,7 +147,7 @@ public class FormHttpMessageWriter implements HttpMessageWriter formData, Charset charset) { + protected String serializeForm(MultiValueMap formData, Charset charset) { StringBuilder builder = new StringBuilder(); formData.forEach((name, values) -> values.forEach(value -> { diff --git a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java index d2b45736e5..f760a118f9 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java @@ -298,25 +298,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter - values.forEach(value -> { - try { - if (builder.length() != 0) { - builder.append('&'); - } - builder.append(URLEncoder.encode(name, charset.name())); - if (value != null) { - builder.append('='); - builder.append(URLEncoder.encode(value, charset.name())); - } - } - catch (UnsupportedEncodingException ex) { - throw new IllegalStateException(ex); - } - })); - - final byte[] bytes = builder.toString().getBytes(charset); + final byte[] bytes = serializeForm(formData, charset).getBytes(charset); outputMessage.getHeaders().setContentLength(bytes.length); if (outputMessage instanceof StreamingHttpOutputMessage) { @@ -340,6 +322,28 @@ public class FormHttpMessageConverter implements HttpMessageConverter formData, Charset charset) { + StringBuilder builder = new StringBuilder(); + formData.forEach((name, values) -> + values.forEach(value -> { + try { + if (builder.length() != 0) { + builder.append('&'); + } + builder.append(URLEncoder.encode(name, charset.name())); + if (value != null) { + builder.append('='); + builder.append(URLEncoder.encode(value, charset.name())); + } + } + catch (UnsupportedEncodingException ex) { + throw new IllegalStateException(ex); + } + })); + + return builder.toString(); + } + private void writeMultipart(final MultiValueMap parts, HttpOutputMessage outputMessage) throws IOException {