Class MultipartHttpMessageWriter
java.lang.Object
org.springframework.http.codec.LoggingCodecSupport
org.springframework.http.codec.multipart.MultipartWriterSupport
org.springframework.http.codec.multipart.MultipartHttpMessageWriter
- All Implemented Interfaces:
- HttpMessageWriter<MultiValueMap<String,- ?>> 
public class MultipartHttpMessageWriter
extends MultipartWriterSupport
implements HttpMessageWriter<MultiValueMap<String,?>> 
HttpMessageWriter for writing a MultiValueMap<String, ?>
 as multipart form data, i.e. "multipart/form-data", to the body
 of a request.
 The serialization of individual parts is delegated to other writers.
 By default only String and Resource parts are supported but
 you can configure others through a constructor argument.
 
This writer can be configured with a FormHttpMessageWriter to
 delegate to. It is the preferred way of supporting both form data and
 multipart data (as opposed to registering each writer separately) so that
 when the MediaType is not specified and generics are not present on
 the target element type, we can inspect the values in the actual map and
 decide whether to write plain form data (String values only) or otherwise.
- Since:
- 5.0
- Author:
- Sebastien Deleuze, Rossen Stoyanchev
- See Also:
- 
Field SummaryFields inherited from class org.springframework.http.codec.multipart.MultipartWriterSupportDEFAULT_CHARSETFields inherited from class org.springframework.http.codec.LoggingCodecSupportlogger
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor with a default list of part writers (String and Resource).MultipartHttpMessageWriter(Supplier<List<HttpMessageWriter<?>>> partWritersSupplier, @Nullable HttpMessageWriter<MultiValueMap<String, String>> formWriter) Constructor with a supplier for an explicit list of writers for serializing parts and a writer for plain form data to fall back when no media type is specified and the actual map consists of String values only.MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters) Constructor with explicit list of writers for serializing parts.MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters, @Nullable HttpMessageWriter<MultiValueMap<String, String>> formWriter) Constructor with explicit list of writers for serializing parts and a writer for plain form data to fall back when no media type is specified and the actual map consists of String values only.
- 
Method SummaryModifier and TypeMethodDescriptionbooleancanWrite(ResolvableType elementType, @Nullable MediaType mediaType) Whether the given object type is supported by this writer.Return the configured form writer.Return the configured part writers.reactor.core.publisher.Mono<Void> write(Publisher<? extends MultiValueMap<String, ?>> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints) Write a given stream of object to the output message.Methods inherited from class org.springframework.http.codec.multipart.MultipartWriterSupportgenerateBoundaryLine, generateLastLine, generateMultipartBoundary, generateNewLine, generatePartHeaders, getCharset, getMultipartMediaType, getWritableMediaTypes, setCharsetMethods 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, getWritableMediaTypes, write
- 
Constructor Details- 
MultipartHttpMessageWriterpublic MultipartHttpMessageWriter()Constructor with a default list of part writers (String and Resource).
- 
MultipartHttpMessageWriterConstructor with explicit list of writers for serializing parts.
- 
MultipartHttpMessageWriterpublic MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters, @Nullable HttpMessageWriter<MultiValueMap<String, String>> formWriter) Constructor with explicit list of writers for serializing parts and a writer for plain form data to fall back when no media type is specified and the actual map consists of String values only.- Parameters:
- partWriters- the writers for serializing parts
- formWriter- the fallback writer for form data,- nullby default
 
- 
MultipartHttpMessageWriterpublic MultipartHttpMessageWriter(Supplier<List<HttpMessageWriter<?>>> partWritersSupplier, @Nullable HttpMessageWriter<MultiValueMap<String, String>> formWriter) Constructor with a supplier for an explicit list of writers for serializing parts and a writer for plain form data to fall back when no media type is specified and the actual map consists of String values only.- Parameters:
- partWritersSupplier- the supplier for writers for serializing parts
- formWriter- the fallback writer for form data,- nullby default
- Since:
- 6.0.3
 
 
- 
- 
Method Details- 
getPartWriters
- 
getFormWriterReturn the configured form writer.- Since:
- 5.1.13
 
- 
canWriteDescription copied from interface:HttpMessageWriterWhether the given object type is supported by this writer.- Specified by:
- canWritein interface- HttpMessageWriter<MultiValueMap<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, ?>> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage outputMessage, 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,- ?>> 
- 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)
- outputMessage- the message to write to
- hints- additional information about how to encode and write
- Returns:
- indicates completion or error
 
 
-