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>>
HttpMessageWriterfor writing aMultiValueMap<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, thecanWrite(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
MultipartHttpMessageWriterconfigured with this writer as the fallback for writing plain form data.- Since:
- 5.0
- Author:
- Sebastien Deleuze, Rossen Stoyanchev
- See Also:
MultipartHttpMessageWriter
Field Summary
Fields Modifier and Type Field Description static CharsetDEFAULT_CHARSETThe default charset used by the writer.Fields inherited from class org.springframework.http.codec.LoggingCodecSupport
logger
Constructor Summary
Constructors Constructor Description FormHttpMessageWriter()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanWrite(ResolvableType elementType, MediaType mediaType)Whether the given object type is supported by this writer.CharsetgetDefaultCharset()Return the configured default charset.protected MediaTypegetMediaType(MediaType mediaType)List<MediaType>getWritableMediaTypes()Return theMediaType's that this writer supports.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(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.Methods inherited from class org.springframework.http.codec.LoggingCodecSupport
isEnableLoggingRequestDetails, setEnableLoggingRequestDetails
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.http.codec.HttpMessageWriter
write
Field Detail
DEFAULT_CHARSET
public static final Charset DEFAULT_CHARSET
The default charset used by the writer.
Constructor Detail
FormHttpMessageWriter
public FormHttpMessageWriter()
Method Detail
setDefaultCharset
public 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.By default this is set to "UTF-8".
getDefaultCharset
public Charset getDefaultCharset()
Return the configured default charset.
getWritableMediaTypes
public List<MediaType> getWritableMediaTypes()
Description copied from interface:HttpMessageWriterReturn theMediaType's that this writer supports.- Specified by:
getWritableMediaTypesin interfaceHttpMessageWriter<MultiValueMap<String,String>>
canWrite
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType)
Description copied from interface:HttpMessageWriterWhether the given object type is supported by this writer.- Specified by:
canWritein interfaceHttpMessageWriter<MultiValueMap<String,String>>- Parameters:
elementType- the type of object to checkmediaType- the media type for the write (possiblynull)- Returns:
trueif writable,falseotherwise
write
public 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)
Description copied from interface:HttpMessageWriterWrite an given stream of object to the output message.- Specified by:
writein interfaceHttpMessageWriter<MultiValueMap<String,String>>- Parameters:
inputStream- the objects to writeelementType- the type of objects in the stream which must have been previously checked viaHttpMessageWriter.canWrite(ResolvableType, MediaType)mediaType- the content type for the write (possiblynullto 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 write- Returns:
- indicates completion or error
getMediaType
protected MediaType getMediaType(@Nullable MediaType mediaType)
serializeForm
protected String serializeForm(MultiValueMap<String,String> formData, Charset charset)