public class FormHttpMessageWriter extends java.lang.Object implements HttpMessageWriter<MultiValueMap<java.lang.String,java.lang.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 java.nio.charset.Charset |
DEFAULT_CHARSET |
private java.nio.charset.Charset |
defaultCharset |
private static java.util.List<MediaType> |
MEDIA_TYPES |
private static ResolvableType |
MULTIVALUE_TYPE |
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.
|
java.nio.charset.Charset |
getDefaultCharset()
Return the configured default charset.
|
private java.nio.charset.Charset |
getMediaTypeCharset(MediaType mediaType) |
java.util.List<MediaType> |
getWritableMediaTypes()
Return the
MediaType 's that this writer supports. |
private java.lang.String |
serializeForm(MultiValueMap<java.lang.String,java.lang.String> form,
java.nio.charset.Charset charset) |
void |
setDefaultCharset(java.nio.charset.Charset charset)
Set the default character set to use for writing form data when the response
Content-Type header does not explicitly specify it.
|
<any> |
write(<any> inputStream,
ResolvableType elementType,
MediaType mediaType,
ReactiveHttpOutputMessage message,
java.util.Map<java.lang.String,java.lang.Object> hints)
Write an given stream of object to the output message.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
write
public static final java.nio.charset.Charset DEFAULT_CHARSET
private static final ResolvableType MULTIVALUE_TYPE
private static final java.util.List<MediaType> MEDIA_TYPES
private java.nio.charset.Charset defaultCharset
public void setDefaultCharset(java.nio.charset.Charset charset)
By default this is set to "UTF-8".
public java.nio.charset.Charset getDefaultCharset()
public java.util.List<MediaType> getWritableMediaTypes()
HttpMessageWriter
MediaType
's that this writer supports.getWritableMediaTypes
in interface HttpMessageWriter<MultiValueMap<java.lang.String,java.lang.String>>
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType)
HttpMessageWriter
canWrite
in interface HttpMessageWriter<MultiValueMap<java.lang.String,java.lang.String>>
elementType
- the type of object to checkmediaType
- the media type for the write, possibly null
true
if writable, false
otherwisepublic <any> write(<any> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, java.util.Map<java.lang.String,java.lang.Object> hints)
HttpMessageWriter
write
in interface HttpMessageWriter<MultiValueMap<java.lang.String,java.lang.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 writeprivate java.nio.charset.Charset getMediaTypeCharset(@Nullable MediaType mediaType)
private java.lang.String serializeForm(MultiValueMap<java.lang.String,java.lang.String> form, java.nio.charset.Charset charset)