Package org.springframework.http.codec
Class FormHttpMessageWriter
java.lang.Object
org.springframework.http.codec.LoggingCodecSupport
org.springframework.http.codec.FormHttpMessageWriter
- All Implemented Interfaces:
- HttpMessageWriter<MultiValueMap<String,- String>> 
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.
- Since:
- 5.0
- Author:
- Sebastien Deleuze, Rossen Stoyanchev
- See Also:
- 
Field SummaryFieldsFields inherited from class org.springframework.http.codec.LoggingCodecSupportlogger
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleancanWrite(ResolvableType elementType, MediaType mediaType) Whether the given object type is supported by this writer.Return the configured default charset.protected MediaTypegetMediaType(MediaType mediaType) Return the content type used to write forms, either the given media type or otherwiseapplication/x-www-form-urlencoded.Return the list of media types supported by this Writer.protected StringserializeForm(MultiValueMap<String, String> formData, Charset charset) voidsetDefaultCharset(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(Publisher<? extends MultiValueMap<String, String>> inputStream, ResolvableType elementType, MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints) Write a given stream of object to the output message.Methods inherited from class org.springframework.http.codec.LoggingCodecSupportisEnableLoggingRequestDetails, setEnableLoggingRequestDetailsMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.http.codec.HttpMessageWritergetWritableMediaTypes, write
- 
Field Details- 
DEFAULT_CHARSETThe default charset used by the writer.
 
- 
- 
Constructor Details- 
FormHttpMessageWriterpublic FormHttpMessageWriter()
 
- 
- 
Method Details- 
setDefaultCharsetSet the default character set to use for writing form data when the response Content-Type header does not explicitly specify it.By default this is set to "UTF-8". 
- 
getDefaultCharsetReturn the configured default charset.
- 
getWritableMediaTypesDescription copied from interface:HttpMessageWriterReturn the list of media types supported by this Writer. The list may not apply to every possible target element type and calls to this method should typically be guarded viacanWrite(elementType, null). The list may also exclude media types supported only for a specific element type. Alternatively, useHttpMessageWriter.getWritableMediaTypes(ResolvableType)for a more precise list.- Specified by:
- getWritableMediaTypesin interface- HttpMessageWriter<MultiValueMap<String,- String>> 
- Returns:
- the general list of supported media types
 
- 
canWriteDescription copied from interface:HttpMessageWriterWhether the given object type is supported by this writer.- Specified by:
- canWritein interface- HttpMessageWriter<MultiValueMap<String,- String>> 
- Parameters:
- elementType- the type of object to check
- mediaType- the media type for the write (possibly- null)
- Returns:
- trueif writable,- falseotherwise
 
- 
writepublic reactor.core.publisher.Mono<Void> write(Publisher<? extends MultiValueMap<String, String>> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints) Description copied from interface:HttpMessageWriterWrite a given stream of object to the output message.- Specified by:
- writein interface- HttpMessageWriter<MultiValueMap<String,- String>> 
- Parameters:
- inputStream- the objects to write
- elementType- 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- nullto indicate that the default content type of the writer must be used)
- message- the message to write to
- hints- additional information about how to encode and write
- Returns:
- indicates completion or error
 
- 
getMediaTypeReturn the content type used to write forms, either the given media type or otherwiseapplication/x-www-form-urlencoded.- Parameters:
- mediaType- the media type passed to- write(org.reactivestreams.Publisher<? extends org.springframework.util.MultiValueMap<java.lang.String, java.lang.String>>, org.springframework.core.ResolvableType, org.springframework.http.MediaType, org.springframework.http.ReactiveHttpOutputMessage, java.util.Map<java.lang.String, java.lang.Object>), or- null
- Returns:
- the content type to use
 
- 
serializeForm
 
-