From 48c2cc18b97362bd526e65a990e688fbbf296bb4 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 31 Oct 2017 09:21:09 -0400 Subject: [PATCH] Update form + multipart data Javadoc on BodyInserters Issue: SPR-16118 --- .../web/reactive/function/BodyInserters.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java index 296680d4282..3a76cc7e4cc 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java @@ -32,7 +32,6 @@ import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.http.client.reactive.ClientHttpRequest; import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.codec.ServerSentEvent; -import org.springframework.http.codec.multipart.Part; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.util.Assert; @@ -57,7 +56,7 @@ public abstract class BodyInserters { ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, String.class); private static final ResolvableType MULTIPART_VALUE_TYPE = ResolvableType.forClassWithGenerics( - MultiValueMap.class, String.class, Part.class); + MultiValueMap.class, String.class, Object.class); private static final BodyInserter EMPTY = (response, context) -> response.setComplete(); @@ -177,8 +176,14 @@ public abstract class BodyInserters { } /** - * Return a {@code BodyInserter} that writes the given {@code MultiValueMap} as URL-encoded - * form data. + * Return a {@code BodyInserter} that writes the given {@code MultiValueMap} + * as URL-encoded form data. + * + *

Note: you can also use the {@code syncBody(Object)} + * method in the request builders of both the {@code WebClient} and + * {@code WebTestClient}. In that case setting the content type is not + * required. Just make sure the map contains String values only. + * * @param formData the form data to write to the output message * @return a {@code BodyInserter} that writes form data */ @@ -198,8 +203,15 @@ public abstract class BodyInserters { } /** - * Return a {@code BodyInserter} that writes the given {@code MultiValueMap} as Multipart - * data. + * Return a {@code BodyInserter} that writes the given {@code MultiValueMap} + * as multipart data. + * + *

Note: you can also use the {@code syncBody(Object)} + * method in the request builders of both the {@code WebClient} and + * {@code WebTestClient}. In that case setting the content type is optional. + * Just make sure the {@code MultiValueMap} contains at least one non-String + * value or otherwise it would be interpreted as plan form data. + * * @param multipartData the form data to write to the output message * @return a {@code BodyInserter} that writes form data */