@ -384,7 +384,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
private void writeForm ( MultiValueMap < String , Object > formData , @Nullable MediaType contentType ,
private void writeForm ( MultiValueMap < String , Object > formData , @Nullable MediaType contentType ,
HttpOutputMessage outputMessage ) throws IOException {
HttpOutputMessage outputMessage ) throws IOException {
contentType = getMedia Type ( contentType ) ;
contentType = getFormContent Type ( contentType ) ;
outputMessage . getHeaders ( ) . setContentType ( contentType ) ;
outputMessage . getHeaders ( ) . setContentType ( contentType ) ;
Charset charset = contentType . getCharset ( ) ;
Charset charset = contentType . getCharset ( ) ;
@ -402,15 +402,27 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
}
}
}
}
private MediaType getMediaType ( @Nullable MediaType mediaType ) {
/ * *
if ( mediaType = = null ) {
* Return the content type used to write forms , given the preferred content type .
* By default , this method returns the given content type , but adds the
* { @linkplain # setCharset ( Charset ) charset } if it does not have one .
* If { @code contentType } is { @code null } ,
* { @code application / x - www - form - urlencoded ; charset = UTF - 8 } is returned .
*
* < p > Subclasses can override this method to change this behavior .
* @param contentType the preferred content type , can be { @code null }
* @return the content type to be used
* @since 5 . 2 . 2
* /
protected MediaType getFormContentType ( @Nullable MediaType contentType ) {
if ( contentType = = null ) {
return DEFAULT_FORM_DATA_MEDIA_TYPE ;
return DEFAULT_FORM_DATA_MEDIA_TYPE ;
}
}
else if ( mediaType . getCharset ( ) = = null ) {
else if ( content Type. getCharset ( ) = = null ) {
return new MediaType ( mediaType , this . charset ) ;
return new MediaType ( content Type, this . charset ) ;
}
}
else {
else {
return mediaType ;
return content Type;
}
}
}
}