From 9d963abb7dfb6b0d0a3f6d89a2e60ebd42268146 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 7 Jan 2020 14:00:27 +0000 Subject: [PATCH] Concrete MediaType check in StringHttpMessageConverter Closes gh-23287 --- .../converter/AbstractHttpMessageConverter.java | 4 ++-- .../http/converter/StringHttpMessageConverter.java | 10 +++++----- .../converter/StringHttpMessageConverterTests.java | 14 +++++++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java index 7b873b97b04..cf0674e06a1 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -239,7 +239,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv protected void addDefaultHeaders(HttpHeaders headers, T t, @Nullable MediaType contentType) throws IOException { if (headers.getContentType() == null) { MediaType contentTypeToUse = contentType; - if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) { + if (contentType == null || !contentType.isConcrete()) { contentTypeToUse = getDefaultContentType(t); } else if (MediaType.APPLICATION_OCTET_STREAM.equals(contentType)) { diff --git a/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java index 7abccf5a06f..d576855d95d 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -102,14 +102,14 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter