Class 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:
  • Constructor Details

    • MultipartHttpMessageWriter

      public MultipartHttpMessageWriter()
      Constructor with a default list of part writers (String and Resource).
    • MultipartHttpMessageWriter

      public MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters)
      Constructor with explicit list of writers for serializing parts.
    • MultipartHttpMessageWriter

      public 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, null by default
  • Method Details