mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 08:24:13 +00:00
Fix wildcard MIME type support in messaging converters
Prior to this commit, the "application/*+json" wildcard MIME type was added to the list of supported MIME types in the JSON messaging converter. This change wasn't fully reflected in the `AbstractMessageConverter`, because only strict matching of type and subtybe were considered. This commit updates the `AbstractMessageConverter` to not only check the type and subtype, but also check whether the supported MIME type includes the one given as a parameter. Fixes gh-36285
This commit is contained in:
+1
-1
@@ -242,7 +242,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
|
||||
return !isStrictContentTypeMatch();
|
||||
}
|
||||
for (MimeType current : getSupportedMimeTypes()) {
|
||||
if (current.getType().equals(mimeType.getType()) && current.getSubtype().equals(mimeType.getSubtype())) {
|
||||
if (current.includes(mimeType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-2
@@ -54,7 +54,7 @@ class MappingJackson2MessageConverterTests {
|
||||
}
|
||||
|
||||
@Test // SPR-12724
|
||||
public void mimetypeParametrizedConstructor() {
|
||||
void mimetypeParametrizedConstructor() {
|
||||
MimeType mimetype = new MimeType("application", "xml", StandardCharsets.UTF_8);
|
||||
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(mimetype);
|
||||
assertThat(converter.getSupportedMimeTypes()).contains(mimetype);
|
||||
@@ -63,7 +63,7 @@ class MappingJackson2MessageConverterTests {
|
||||
}
|
||||
|
||||
@Test // SPR-12724
|
||||
public void mimetypesParametrizedConstructor() {
|
||||
void mimetypesParametrizedConstructor() {
|
||||
MimeType jsonMimetype = new MimeType("application", "json", StandardCharsets.UTF_8);
|
||||
MimeType xmlMimetype = new MimeType("application", "xml", StandardCharsets.UTF_8);
|
||||
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(jsonMimetype, xmlMimetype);
|
||||
@@ -72,6 +72,22 @@ class MappingJackson2MessageConverterTests {
|
||||
.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void supportJsonMimeType() {
|
||||
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, "application/json").build();
|
||||
assertThat(converter.supportsMimeType(message.getHeaders())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void supportVendorJsonMimeTypes() {
|
||||
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, "application/vnd.springframework.type+json").build();
|
||||
assertThat(converter.supportsMimeType(message.getHeaders())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromMessage() {
|
||||
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
|
||||
|
||||
Reference in New Issue
Block a user