public class FormHttpMessageWriter extends LoggingCodecSupport implements HttpMessageWriter<MultiValueMap<String,String>>
HttpMessageWriter
for writing a MultiValueMap<String, String>
as HTML form data, i.e. "application/x-www-form-urlencoded"
, to the
body of a request.
Note that unless the media type is explicitly set to
MediaType.APPLICATION_FORM_URLENCODED
, the canWrite(org.springframework.core.ResolvableType, org.springframework.http.MediaType)
method
will need generic type information to confirm the target map has String values.
This is because a MultiValueMap with non-String values can be used to write
multipart requests.
To support both form data and multipart requests, consider using
MultipartHttpMessageWriter
configured with this writer as the fallback for writing plain form data.
MultipartHttpMessageWriter
Modifier and Type | Field and Description |
---|---|
static Charset |
DEFAULT_CHARSET
The default charset used by the writer.
|
logger
Constructor and Description |
---|
FormHttpMessageWriter() |
Modifier and Type | Method and Description |
---|---|
boolean |
canWrite(ResolvableType elementType,
MediaType mediaType)
Whether the given object type is supported by this writer.
|
Charset |
getDefaultCharset()
Return the configured default charset.
|
protected MediaType |
getMediaType(MediaType mediaType) |
List<MediaType> |
getWritableMediaTypes()
Return the list of media types supported by this Writer.
|
protected String |
serializeForm(MultiValueMap<String,String> formData,
Charset charset) |
void |
setDefaultCharset(Charset charset)
Set the default character set to use for writing form data when the response
Content-Type header does not explicitly specify it.
|
reactor.core.publisher.Mono<Void> |
write(org.reactivestreams.Publisher<? extends MultiValueMap<String,String>> inputStream,
ResolvableType elementType,
MediaType mediaType,
ReactiveHttpOutputMessage message,
Map<String,Object> hints)
Write an given stream of object to the output message.
|
isEnableLoggingRequestDetails, setEnableLoggingRequestDetails
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getWritableMediaTypes, write
public static final Charset DEFAULT_CHARSET
public void setDefaultCharset(Charset charset)
By default this is set to "UTF-8".
public Charset getDefaultCharset()
public List<MediaType> getWritableMediaTypes()
HttpMessageWriter
canWrite(elementType, null)
. The list may also exclude media types
supported only for a specific element type. Alternatively, use
HttpMessageWriter.getWritableMediaTypes(ResolvableType)
for a more precise list.getWritableMediaTypes
in interface HttpMessageWriter<MultiValueMap<String,String>>
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType)
HttpMessageWriter
canWrite
in interface HttpMessageWriter<MultiValueMap<String,String>>
elementType
- the type of object to checkmediaType
- the media type for the write (possibly null
)true
if writable, false
otherwisepublic reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<? extends MultiValueMap<String,String>> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String,Object> hints)
HttpMessageWriter
write
in interface HttpMessageWriter<MultiValueMap<String,String>>
inputStream
- the objects to writeelementType
- the type of objects in the stream which must have been
previously checked via HttpMessageWriter.canWrite(ResolvableType, MediaType)
mediaType
- the content type for the write (possibly null
to
indicate that the default content type of the writer must be used)message
- the message to write tohints
- additional information about how to encode and writeprotected String serializeForm(MultiValueMap<String,String> formData, Charset charset)