From c6a655275df9baca4c9d35a01e0fa93308b8f308 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 20 Mar 2019 09:32:48 -0400 Subject: [PATCH] Allow overriding of FormHttpMessageWriter#getMediaType Closes gh-22588 --- .../springframework/http/codec/FormHttpMessageWriter.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java index ea93d9f223..37861c0393 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -127,8 +127,7 @@ public class FormHttpMessageWriter extends LoggingCodecSupport mediaType = getMediaType(mediaType); message.getHeaders().setContentType(mediaType); - Charset charset = mediaType.getCharset(); - Assert.notNull(charset, "No charset"); // should never occur + Charset charset = mediaType.getCharset() != null ? mediaType.getCharset() : getDefaultCharset(); return Mono.from(inputStream).flatMap(form -> { logFormData(form, hints); @@ -140,7 +139,7 @@ public class FormHttpMessageWriter extends LoggingCodecSupport }); } - private MediaType getMediaType(@Nullable MediaType mediaType) { + protected MediaType getMediaType(@Nullable MediaType mediaType) { if (mediaType == null) { return DEFAULT_FORM_DATA_MEDIA_TYPE; } -- GitLab